|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-06 15:42 UTC] csaba at alum dot mit dot edu
This bug concerns & and = in cookies which is supported (ie. document.cookies) in my Netscape 6.1 and IE 5.5 on my Win2K, Apache 2.0.35, PHP 4.2 (as module) system.
I have made the following test: First, using Header in the index.php test file below, I set a cookie by the name of CookieTest to the following: Var1=Hi%20Mom&Var2=Frob
The script below demonstrates that the cookie is received by the browser, but PHP fails to put the cookie into $_COOKIE (and $_REQUEST).
<html><head><title>Testing cookies</title></head><body>
<?php
Header("Set-Cookie: CookieTest=Var1=Hi%20Mom&Var2=Frob; expires=Thu, 07-May-02 00:00:00 GMT; path=/");
$aHeaders = getallheaders();
foreach ($aHeaders as $key=>$hdr)
print "<br>Header $key: $hdr\r\n";
?>
<br><br>Cookies according to browser:<br>
<script>document.write(document.cookie)</script>
<?php phpinfo(); ?>
</body></html>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 00:00:02 2025 UTC |
That's nice. I agree with your statement, but it has no bearing on my bug report. That's why I've marked the status Open again. I'll spell out what you are looking for. You have to run the test twice because on the first invocation (from client to server) no cookies have been set yet, as you point out. The second invocation on IE can be accomplished by an F5 button, while with netscape, you may have to clear the disk/memory cache since the client may not run out to the server otherwise. Upon this (second) test, you will notice that in the section printed out by the php headers, we have an entry (correctly) reading: Header Cookie: CookieTest=Var1=Hi%20Mom&Var2=Frob Right below this we have another entry (correctly) reading: Cookies according to browser: CookieTest=Var1=Hi%20Mom&Var2=Frob So now we know that the cookie we set was correctly received by the browser, and that the server, in turn, has correctly received the cookie that was on the client machine. Now let's see what PHP does with it. In the PHP Variables (next to last) section of the phpinfo() we have two entries reading: _COOKIE["CookieTest"] | Var1=Hi Mom&Var2=Frob _SERVER["HTTP_COOKIE"] | CookieTest=Var1=Hi%20Mom&Var2=Frob Evidently, PHP has interpreted that %20 as a space. I have not been able to find any documentation for this behaviour, and that is what I am reporting. Browser documentation generally encourages using escape() to ensure that no illegal characters are embedded within a cookie, but this is not the only way. Ultimitely, it means that I can't get all cookie values or use alternate encoding schemes unless I go to the original _SERVER["HTTP_COOKIE"].