I know I’m not supposed to cross post, but I let my other thread up for a day in the Javascript forum with no success and I think it might be because it’s being looked at by the wrong audience. Wonder if some the PHP experts can spot a flaw somewhere that I have missed.
I’m thinking this has something to do with headers. I am using JS to send an ajax request to set a cookie when a user clicks a div. The request gets sent and the server-side script get’s executed properly.
This is the response:
[code]
Date Tue, 02 Mar 2010 14:56:56 GMT
Server Apache/2.2.14 (Win32) PHP/5.2.10
X-Powered-By PHP/5.2.10
Set-Cookie jakscolor=green; expires=Tue, 01-Mar-2011 14:56:56 GMT
Content-Length 0
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html
All well and good, I can see that my cookie has been set (jakscolor).
But when I refresh and the page and do print_r($_COOKIE) I get nada, nil, zip.
Interestingly enough, I found out that if I execute the script two of three times in the same session, I can see by looking at the request header of the subsequent request to the response I showed above:
[code]
Host myserver.dev
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
Accept */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Content-Type application/x-www-form-urlencoded
X-Requested-With XMLHttpRequest
Referer http://myserver.dev/minutemuffler/admin/
Cookie jakscolor=green; __utma=260484881.821254434.1264890648.1265124054.1266440794.7; __utmz=260484881.1264890648.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=crk4ov8e3gfmgipgfr2252n0e2
that my last cookie was set (as can be noted by jakscolor=green in the Request Header).
But it’s not actually getting set, because when the page is refreshed, like I said, $_COOKIE is empty…..WTF?