Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies

Status
Not open for further replies.

BB101

Programmer
May 23, 2001
337
GB
Wasn't sure if this belonged here, in the javascript section or somewhere completely different, but you lot seem like a nice bunch, so here goes.

I'm basically having the same problem as this chap:
This problem is frustrating and annoying and I'm at my wits end. Does anyone have a solution? Should I write code to overide my $_COOKIE variable using $_ENV['HTTP_COOKIE']? Any help is appreciated.

--BB
 
I have written a bodge that seems to be doing the trick, I submit it here for your review; comments and suggestions welcome:

Code:
$c = explode("; ", $_SERVER['HTTP_COOKIE']);
$cv = array();
foreach ($c as $p) {
  list($k,$v) = explode("=", $p);
  if (isset($cv[$k])) continue;
  $cv[$k] = $v;
}
$_COOKIE = $cv;

--BB
 
I don't know -- I didn't bother to look at the external page, as I thought if the problem weren't important enough to describe here, it's not important.

Why are you overwriting $_COOKIE with the raw cookies sent to the server? Are you having some kind of problem with PHP's expansion of cookies? What version of PHP are you running?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
The problem arrises when IE keeps duplicate cookies with the same key. The version of PHP is not important, I get the same problem regardless of whether I use Javascript, meta tags or http headers, i am however running PHP5.

PHP reads the HTTP_COOKIE variable and overwrites the values with the last value, IE sets the first value when you update, so I end up with a dead cookie I cannot set or delete. This bodge merely makes PHP use the first cookie and not the last one.

--BB
 
Here's a dump of the HTTP_COOKIE variable to add clarity:[HTTP_COOKIE] => ayn=MDEyMjA0MjAzNDc4QjE5SlRhdUxUOEE2Z2F4VWt5VnBRbmRDVG83NkgxOUM3MWR5SExiQ1Rvag; PHPSESSID=oakp2ruq120pt3ja1n83qqo267; ayn=MDMwNDM1NTEzNDc5clMzRkhQb2FIRFVSOVBqN2xla09kdUl3SHEwUkdZM3dHUzFNMDI5VE9J; PHPSESSID=oakp2ruq120pt3ja1n83qqo267



--BB
 
Yeah, the bug is in IE.

From what I can tell, in certain subversions of IE, when you set a cookie in the domain "foo.com" and a cookie with the same name in " IE will send duplicate cookies. I guess the longterm workaround would be to be explicit in the domain in which the script sets cookies.



I don't see anything wrong with your code.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you very much, I think I'll add a little script to force people to go from the non www. url to the www. url.

Again, thank you.

--BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top