#33627 [Opn->Bgs]: Setcookie problems

From: Date: Tue, 12 Jul 2005 10:22:30 +0000
Subject: #33627 [Opn->Bgs]: Setcookie problems
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-81722@lists.php.net to get a copy of this message
ID: 33627 Updated by: tony2001@php.net Reported By: weathermon at optusnet dot com dot au -Status: Open +Status: Bogus Bug Type: *General Issues Operating System: Linux 2.4.18-3smp #1 PHP Version: 4.4.0 New Comment: http://php.net/setcookie : Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);. Previous Comments: ------------------------------------------------------------------------ [2005-07-12 12:17:35] weathermon at optusnet dot com dot au I have upgraded to version 4.4.0 of php and still no go. test.php?thumbview=0 cookie set! Thumbview: 0 Cookie Value: 0 test.php?thumbview=1 cookie set! Thumbview: 1 Cookie Value: 0 I refresh the page again and this time it sets the cookie: test.php?thumbview=1 cookie set! Thumbview: 1 Cookie Value: 1 What I noticed was that when I ran the last test.php?thumbview=1, I didn't have to even put in ?thumbview=1, I just typed in test.php and this is what it said: Thumbview: Cookie Value: 1 So, my understanding is that it's setting the cookie, however if I try and read it in the same session, it retrieves the data it saved before for some reason... and when I just run the test.php again without any parameters, it reads the saved cookie properly... When I executed this from when the Cookie was set to 1 before, this is what I got: test.php?thumbview=blah cookie set! Thumbview: 1 Cookie Value: 1 test.php Thumbview: Cookie Value: blah So yeah... it definitely seems to be saving the cookie.. but when I try and read it in the same session, it's retrieving the old data from somewhere still, and will only read the new data on the next refresh ------------------------------------------------------------------------ [2005-07-10 09:03:28] tony2001@php.net Thank you for taking the time to report a problem with PHP. Unfortunately you are not using a current version of PHP -- the problem might already be fixed. Please download a new PHP version from http://www.php.net/downloads.php If you are able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PHP. ------------------------------------------------------------------------ [2005-07-10 05:35:18] weathermon at optusnet dot com dot au Description: ------------ The submit bug report doesn't have my PHP version in there, I am using 4.3.2. When I use setcookie, it seems to only be setting the cookie every 2nd time I load the page for some reason. I am getting the value from $_GET and storing that in the cookie. Just for debugging purposes, I am printing the thumbview parameter and the cookie value each time it's run. Basically I want the cookie to be set to the thumbview's value each time I change it. I have no idea why it gets set only when I refresh the page a second time. Reproduce code: --------------- <?php if ($_GET["thumbview"]!="") { $sdata = $_GET["thumbview"]; if (!setcookie ("dirlisting", $sdata, time()+3600)) { print ("cookie NOT set!"); } else { print ("cookie set!"); } } print "<br>Thumbview: ".$sdata; print "<br>Cookie Value: ".$_COOKIE["dirlisting"]; ?> Expected result: ---------------- test.php?thumbview=0 cookie set! Thumbview: 0 Cookie Value: 0 test.php?thumbview=1 cookie set! Thumbview: 1 Cookie Value: 1 Actual result: -------------- test.php?thumbview=0 cookie set! Thumbview: 0 Cookie Value: 0 test.php?thumbview=1 cookie set! Thumbview: 1 Cookie Value: 0 I refresh the page again and this time it sets the cookie: test.php?thumbview=1 cookie set! Thumbview: 1 Cookie Value: 1 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33627&edit=1

« previous php.bugs (#81722) next »