php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28409 setcookie doesn't seem to work
Submitted: 2004-05-15 13:50 UTC Modified: 2004-05-24 01:00 UTC
Votes:9
Avg. Score:4.2 ± 0.9
Reproduced:7 of 8 (87.5%)
Same Version:2 (28.6%)
Same OS:4 (57.1%)
From: harshit at oinka dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.3.5 OS: Windows 2000 Professional
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-05-15 13:50 UTC] harshit at oinka dot com
Description:
------------
The setcookie function call as expected was supposed to set a desired cookie. However due to the presence of a header function immediately after the setcookie call, the setcookie function fails to set the cookie. I was using the header function as a means of redirection. I managed to solve the problrm using a meta refresh but am intrifued as to why setcookie failed to perform its role. I've checked the return value for setcookie, it returns a "true" value.



Reproduce code:
---------------
if(empty($_COOKIE['id']){
  //set cookie for 24 hours
  setcookie("id",123,time()+60*60*24);
  header("Location: redirpage.php");
}else{
  header("Location: mainpage.php");

}

Expected result:
----------------
After checking for the cookie and setting it the code should redirect to redirpage.php. It redirects alright, but does not set the cookie.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-15 19:29 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Also, please indicate what php sapi & webserver are you 
using. 
 [2004-05-15 19:55 UTC] solace at ezmail dot ru
Very strange, but I can advise:
1) Use full URL with host name in location header
2) Output something to browser (echo "anything") after header().
 [2004-05-24 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2004-07-24 04:27 UTC] webmaster at 8interactive dot com
I have the same problem.  PHP version 4.3.3 on Windows NT WIN406 5.0.  I got the cookies to set after I got rid of the header line.  This needs to be fixed.
 [2005-06-16 09:39 UTC] gamarilla at fassgroup dot com dot ar
I have exactly the same problem.
I?m using Windows 2000 Professional and PHP on IIS
Upgraded to PHP 5.0.4 - 31 Mar 2005
md5: fff10991a8e6f3b36ee567eb236ae3f4 
and the problem is still present.
 [2006-04-28 20:49 UTC] apaganini at nassaucountyny dot gov
I have the same issue as well...
If i use an <a> tag to manually move to the next page, the cookie sets, but not if it is redirected to the page with the header statement.
Windows 2000 Professional and PHP on IIS
PHP 5.0.4
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC