|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-08-24 05:26 UTC] henrysim78 at yahoo dot com
Description:
------------
I'm using PHP Ver.4.3.2
I have the same problem too, when use setcookie(<cookiename>), Cookie is
set to %00 instead of erased.
The problem happen when it hit this syntax :
if(isset($_COOKIE['register'])) {echo
$_COOKIE['register'];}
Neither isset or !empty function could detect whether it's empty or not.
It always return true, so it will try to display the value
$_COOKIE['register'] that has been deleted. It returned error message
:
Notice: Uninitialized string offset: 0 in D:\My Web\register.php on line
186
Thanks in advance.
Reproduce code:
---------------
setcookie("register[one]","Bill"); //Set the cookie
setcookie("register[two]","Jim");
setcookie("register") //Delete the cookie
if(isset($_COOKIE['register']['one']))
{echo $_COOKIE['register']['one'];
} else
{echo "COOKIE Not Exist";
}
Expected result:
----------------
It should display "COOKIE Not Exist" as the cookie has been deleted.
Actual result:
--------------
It try to display the value of deleted COOKIE. It generated error :
Notice: Uninitialized string offset: 0 in D:\My Web\register.php on line
186
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 25 23:00:01 2025 UTC |
Cookies are set with the name you set them to. You also need to delete them with the name(s) you set them to. Thus deleting these cookies: setcookie("register[one]"); setcookie("register[two]"); RTFM: "You may also set array cookies by using array notation in the cookie name. This has the effect of setting as many cookies as you have array elements, but when the cookie is received by your script, the values are all placed in an array with the cookie's name"Thanks, it did work now. But a question keep remain, why PHP seem recognize those COOKIEs still exist? Setcookie("register") do eliminate all of the "Register" array inside the COOKIE, as when i checked with print_r ($_COOKIE) it give result : Array ( [PHPSESSID] => f0cf5ed37c49006512def3576cfb7171 [register] => ) It means [register][one], [register][two] are no longer exist so the "isset" function suppose to return "FALSE"?