0

I have worked on a little script which can be used to set cookies if you know the location. For example, this code below:

$(window).load(function () {
    $('body').append('<iframe src="http://mydomain.com/setcookie?data=abc123" width="1" height="1" frameborder="0"></iframe>');
}); //sets cookie from desired location, you need its exact id/location.

Does anybody know any good method for taking a created cookie and then applying it to all visitors which visits (using this script), but not knowing the location?

I have thought of extracting the created cookie and then taking the information and creating my own php cookie, is this possible? tell me if I'm being unclear or something..

2
  • You want all visitors to share the same cookie? Commented May 15, 2013 at 13:42
  • The example which is displayed above automatically sets the desired cookie to anybody who visits the page, my question is about how you set cookies to those you don't have the action id of Commented May 15, 2013 at 13:45

1 Answer 1

2

Try Jquery Cookie pluging: https://github.com/carhartl/jquery-cookie it will help you to create cookies in the client-side, you can then use standard PHP to read those cookies in the server-side.

[edit]

You can try to send to the server the URL from where the script was executed:

'<iframe src="http://mydomain.com/setcookie?data=abc123&location=' + 
 window.location.host + '"...

It should allow you to find where is it coming from, but it is not really secure as If I know a bit of coding I just need to find a trusted host and change for it window.location.host you should better check the request in the server side ($_SERVER['HTTP_REFERER']).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, it was very helpful. The plugin is very useful for me when testing with cookies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.