php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #15441 Cookie is set to %00 instead of erased
Submitted: 2002-02-08 00:26 UTC Modified: 2002-02-08 12:27 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: paul dot lists at burney dot ws Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.1 OS: Solaris 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: paul dot lists at burney dot ws
New email:
PHP Version: OS:

 

 [2002-02-08 00:26 UTC] paul dot lists at burney dot ws
Using PHP 4.1.x, the following code, which is intended to 
delete a cookie, instead replaces the value with %00 (ascii 
entity null?)

Cookies are set with the following:

		setcookie($username_cookie,'username');
		setcookie($password_cookie,md5('password'));

Cookies are deleted with the following:

			setcookie($username_cookie);
			setcookie($password_cookie);

Yes, the $username_cookie and $password_cookie variables 
have values.

The above is case (a) in the documentation, the simplest 
case.

I've tried this on all the systems I have access to.

Affected: 
Solaris 7, PHP 4.1.0
Red Hat 7.1, PHP 4.1.1

Not Affected: 
Red Hat 7.1, PHP 4.04pl1
Mac OS X 10.1.2, PHP 4.0.6
Solaris 7, PHP 4.06

One affected system that I've used is on a web host 
(communitech.net, who just very recently moved to PHP 4.1.0 
from 3.0.9, Solaris 7).  The other is on the freshly setup 
intranet server at my employer (Linux 4.1.1).

Here's the configuration line (Solaris 7, PHP 4.1.0):

?'./configure' '--with-mysql=/usr/local/mysql' '--with-
curl=/root/src/curl/curl-7.9.3' '--with-xml' '--with-
apache=/root/src/apache/apache-fp_1.3.3'

And the one from Red Hat 7, PHP 4.1.1:

'./configure' '--prefix=/usr/local' '--with-apache=/usr/
local/src/apache/Apachetoolbox-1.5.50/apache_1.3.22' '--
enable-exif' '--enable-track-vars' '--with-calendar=shared' 
'--enable-safe-mode' '--enable-magic-quotes' '--enable-
trans-sid' '--enable-wddx' '--enable-ftp' '--with-gd=/usr/
local' '--with-zlib' '--enable-gd-native-tt' '--with-t1lib=
/usr/local' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '-
-with-zlib-dir=/usr' '--with-ttf' '--with-freetype-dir=/
usr' '--with-imap=/usr/local' '--with-openssl=/usr' '--
with-mysql=/usr/local/mysql' '--with-pgsql' '--with-ldap'

The same code works in previous versions of PHP to 4.1, as 
indicated above.  I've tried the code in three different 
browsers so I don't think it is browser dependent.

The actual piece of code is part of a larger system.  I can 
give you the code or access to one of the servers if 
necessary.

Thanks in advance.

Paul Burney
Webmaster
Concord Consortium and UCLA GSE&IS

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-08 00:51 UTC] cnewbill@php.net
From the setcookie page.

"When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser."

Try this
setcookie($username_cookie, '', time()-3600);

-Chris

 [2002-02-08 10:00 UTC] paul dot lists at burney dot ws
On the documentation page it says:

"When deleting a cookie you should assure that the 
expiration date is in
the past, to trigger the removal mechanism in your 
browser."

However, since the first delete cookie example doesn't have 
any value for the "expire" argument, it is implied that if 
called with only the variable name, PHP will automatically 
assure that the expiration date is in the past.

The code you provided works, of course.  There is 
definately a difference in the way that PHP 4.1.x handles 
this than previous versions.

I guess this is now a documentation problem. From the 
setcookie documentation, under setcookie() delete examples, 
the first listed is:

setcookie ("TestCookie");

Which in PHP 4.1.x just sets the cookie to %00 as the 
original bug stated.  I suggest removing that example.

Also the function definition should no longer suggest that 
setcookie only requires one argument.


 [2002-02-08 12:27 UTC] cnewbill@php.net
This bug has been fixed in CVS.
 [2003-08-24 05:12 UTC] henrysim78 at yahoo dot com
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 04:01:27 2024 UTC