php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #19638 setcookie and the null value for the value argument
Submitted: 2002-09-27 13:46 UTC Modified: 2004-07-26 23:31 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: cheatah at tweakers dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.2.3 OS: Any
Private report: No CVE-ID: None
 [2002-09-27 13:46 UTC] cheatah at tweakers dot net
When using the setcookie function, I noted that setting the value to NULL had the following result:

The expire time argument was completely ignored, and automatically set to one year and one second ago. Also the value sent to the browser for this cookie had changed to 'deleted'.

I browsed the PHP source code, and saw my suspicions confirmed, this is the correct behaviour.
Could this be included in the documentation? I really like the following syntax:

setcookie('name', null, null, '/');

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-17 04:55 UTC] Xuefer at 21cn dot com
yes, it's the same problem trouble me.
then same when setcookie('name', '', 0, '/');

the question is: Is 1 year and 1 second enough ?
when a pc lost battery, and turned off, system clock is reset to long long ago.

i dunno if a browser compare the "Expire time" to system clock or "Date: ..." header return by server

the document of php tell us nothing about this.

currently, i have to do:
setcookie('name', "0", 0, '/');
and change my script isset($_COOKIE['name']) to !empty($_COOKIE['name'])
even javascript:
var myc = mygetcookie('name');
if (myc && myc != '0')
{
 //.......
}

hope there's a final solution to this problem :)
 [2004-07-26 23:31 UTC] vrana@php.net
Parameters can be skipped by 0 or '' as documented. How to delete a cookie is nowadays also documented. However I documented that expire is compared to client's time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 05:01:31 2024 UTC