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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cheatah at tweakers dot net
New email:
PHP Version: OS:

 

 [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: Fri May 24 18:01:30 2024 UTC