Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Apologies if this question duplicates some other question, but I can't find one exactly like it in S.O.

I am writing a remotely hosted app, the kind that runs when you put a javascript on your own website page, where the src="some remote javascript.js". so, the script operates by calling every operation as a jsonp ajax. A lot of jsonp housekeeping, but otherwise works surprisingly well.

In the main remote js script, I set a user cookie when the user logs in. It works fine, the cookie is set for a year, and when you return to the page it continues recognizes you.

However, when I try to output the cookie (even after it has been set) using php, my php code does not see it for some reason.

If I alert(document.cookie); the cookie is displayed. If I do a var_dump($_COOKIE); php returns array(0) { }.

This isn't a "you have to reload the page after setting the cookie with javascript" problem.

As far as I know, when I use the Firefox Web Developer extension to View Cookie Information, it is all happening on the same domain.

Looking over many other examples, it is clear that PHP should be able to read a cookie, even if set by javascript.

Even as I write this, I think a glimmer of what the problem is is starting to form in my head, that (possibly) a JSONP'd php script isn't going to see the cookie set by javascript.

share|improve this question
How is your cookie created? Is it on the correct domain/path? – Paul S. Jun 20 at 15:53
A browser won't send a cookie for the different origin. – Your Common Sense Jun 20 at 15:54
Could be a path issue. The Web Developer "View Cookie Information" shows the path as "/". That's the client's path. The application path is "/discussion/". Maybe that's the problem. The domain is identical, though. – Gregory Lewis Jun 20 at 15:58

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.