#33627 [Bgs->Opn]: Setcookie problems
| From: | weathermon at optusnet dot com dot au | Date: | Tue, 12 Jul 2005 10:17:38 +0000 |
| Subject: | #33627 [Bgs->Opn]: Setcookie problems | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-81720@lists.php.net to get a copy of this message | ||
ID: 33627
User updated by: weathermon at optusnet dot com dot au
Reported By: weathermon at optusnet dot com dot au
-Status: Bogus
+Status: Open
Bug Type: *General Issues
Operating System: Linux 2.4.18-3smp #1
-PHP Version: 4.3.11
+PHP Version: 4.4.0
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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