So from my understanding of PHP and cookies, if I use the setcookie()
function, then I get a cookie that is automatically url encoded. And when I go to the $_COOKIE
array, I should get the cookie back, automatically url decoded. Problem is, it seems to be decoding the cookie twice when I look in $_COOKIE
.
Say I have a cookie whose value is "Name|ID|Email", for example:
Joe|123|my+email@somewhere.com
This would be encoded as:
Joe%7C123%7Cmy%2Bemail%40somewhere.com
Notice the plus sign is encoded, so theoretically I ought to get it back if I decode it. Since this is automatically done in $_COOKIE
, I ought to get back what I started with. But instead, I'm getting back:
Joe|123|my email@somewhere.com
Notice the space where the plus used to be. This is what I would expect if I ran an additional urldecode()
on the cookie. But I'm not, so I have no idea why I would be getting a space instead of a plus.
Another interesting twist. A refresh on the page seems to produce the correct output. Any ideas why it's behaving like this?
FYI, to set the initial cookie, I use javascript and escape()
the script to produce the encoded string. Might this be an hand off issue between javascript and PHP?
Thoughts would be appreciated.