note 1041 deleted from function.setcookie by imajes

From: Date: Sat, 06 Apr 2002 21:53:15 +0000
Subject: note 1041 deleted from function.setcookie by imajes
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28784@lists.php.net to get a copy of this message
Hey everyone, I dumped quite a few headers from some popular web sites, and I discovered that the cookies that PHP is sending out are not QUITE the same as these big sites. And, because of these differences, some browsers are not picking up the PHP cookies. I noticed that a lot of you have resorted to using the 'header' method of doing cookies, so, here is my contribution: This code will act as a drop-in replacement for the PHP setcookie function, and you may call it in the same fashion. I just don't handle secure cookie settings, and I don't do array stuff. Other than that, I've tested this on IE3, IE4, IE5, NS3, and NS4. Works for me, and also works with the Location: redirect. Oh, and the notable changes are in the Date spec for expiration, and the ordering of domain, path, and expires. the old PHP way seemed to be out of order ;) function <font color="#5B69A6">MySetCookie</font> ($CkyName, $CkyVal, $exp, $pth, $Domain, $Secure) { static $mycky; $exp = strftime("%A, %d-%b-%Y %H:%M:%S", $exp); $cookiestr = sprintf ("%s=%s; domain=%s; path=%s; expires=%s", $CkyName, $CkyValue, $Domain, $pth, $exp); $mycky = ( ($mycky) ? "$mycky\n" : "") . "Set-Cookie: $cookiestr"; header($mycky); }

« previous php.notes (#28784) next »