Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #13116 : setcookie would not work when expire is set
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 17th July 04:16
php-bugs
External User
 
Posts: 1
Default #13116 : setcookie would not work when expire is set


ID: 13116
Comment by: senglathsamy at laodev dot com
Reported By: gotenforward at yahoo dot com
Status: No Feedback
Bug Type: HTTP related
Operating System: FreeBSD 4.3
PHP Version: 4.0.6
New Comment:

I also have problem as above posted.
my script can not work on FC6 server but it's work well on Win Server

1 test:

setcookie("use","value"); // I can call cookie based on both win and
linux server

2 test:

setcookie("use","value",time()+3600); // I can call cookie based on win
only, But can't call cookie linux server

so, help me to fix this bug, Plz!


Previous Comments:
------------------------------------------------------------------------

[2002-03-08 00:00:04] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a month, 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".

------------------------------------------------------------------------

[2002-02-07 23:05:03] shiflett@php.net

Your code works for me, but I don't have a FreeBSD box to test on nor
an Internet Explorer browser.

However, let's not assume yet that this is a FreeBSD problem, since
that really seems unlikely with such a basic thing. The much more
probable case is that it is an IE bug, as IE has historically had
problems with adhering to HTTP standards specifically with cookies.

If your problem (as you say) is like the other bug you link to, then it
sounds like the problem lies in the browser not returning the cookie
rather than the cookie not being set.

To help investigate this, please check as many of the following things
as you know how:

1) HTTP response your PHP page generates
2) subsequent HTTP request from the browser (meaning, a request after
the cookie has been set)
3) Time (in GMT) on the browser
4) Time (in GMT) on the server
5) URL being used to access the page
6) Domain being used to set the cookie

If the problem doesn't reveal itself after inspecting these things, use
the header function as you did but with all hardcoded values to make
sure you're setting the cookie you think you are and that the date is
sufficiently far in the future to rule out any time synchronization
problems.

Thanks for your help!

Chris

------------------------------------------------------------------------

[2001-09-03 16:47:38] gotenforward at yahoo dot com

Another user experience the same problem like mine

http://www.php.net/bugs.php?id=11492&edit=1

It looks like they are all using FreeBSD

------------------------------------------------------------------------

[2001-09-03 16:33:11] gotenforward at yahoo dot com

I pretty much get the same error as this link

http://www.php.net/bugs.php?id=11478&edit=1

Over a couple hundreds of users, all of them works fine with IE 5.0+
However, some of the user can not login due to the cookie is not set.

Whenever I do

setcookie("username",$user,time()+3600,"/",".domain.com");

Some of the users using IE would not get the cookie.

But when i just change it to

setcookie("username",$user,"","/",".domain.com");

It works. But not setting expire time will not write the cookie to
harddisk, it just stored into memory, which is not what I want.

So, I tried to use the header function and see if that helps.

$time = mktime()+ $config[cookieTTL];
$date = gmdate("l, d-M-Y H:i:s", ($time));
header("Set-Cookie: $cookiename=$tmpstring; expires=$date GMT;
path=/;");

IE still do not pick up the cookie.


Here is a little function I use to store cookie

function putCookie($config,$cookiename, $varname, $data, $send="") {

// function to store cookie, use serialize() to bypass the limit of
using 20 cookies per domain.
// And make it easier to add new cookie later.

//keep this array always static so that when we get out of this
function, it still keep the variable.
static $tmpArray;

$tmpArray[$varname] = $data;

if ($send != "") {
$tmpstring = serialize($tmpArray);
$tmpstring = base64_encode($tmpstring);

$time = mktime()+ $config[cookieTTL];
$date = gmdate("l, d-M-Y H:i:s", ($time));

setCookie($cookiename, $tmpstring, "", $config[cookie_path],
$config[CookieURL]); // now we clean the static array after we send the
cookie

unset($tmpstring);
$tmpArray = "";
unset($tmpArray);
}
}

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=13116&edit=1
  Reply With Quote


  sponsored links


2 19th July 13:05
php-bugs
External User
 
Posts: 1
Default #13116 : setcookie would not work when expire is set


ID: 13116
Comment by: aziz at azizce dot com
Reported By: gotenforward at yahoo dot com
Status: No Feedback
Bug Type: HTTP related
Operating System: FreeBSD 4.3
PHP Version: 4.0.6
New Comment:

[quote = "senglathsamy at laodev dot com"]


//I also have problem as above posted.
//my script can not work on FC6 server but it's work well on Win
Server

//1 test:

//setcookie("use","value"); // I can call cookie based on both win and
//linux server

//2 test:

//setcookie("use","value",time()+3600); // I can call cookie based on
//win
//only, But can't call cookie linux server

//so, help me to fix this bug, Plz!
[/quote]

I was had same problem too. Now it was resolved. (Thanks for help
Hannes)

shiflett said on 7 Feb 2002 ;

3) Time (in GMT) on the browser
4) Time (in GMT) on the server

And I say that's your solution. Compare your computer time(in GMT) with
your remote server time (in GMT) .You'll see that probably times are
different...

Regards...


Previous Comments:
------------------------------------------------------------------------

[2007-04-10 11:34:29] senglathsamy at laodev dot com

I also have problem as above posted.
my script can not work on FC6 server but it's work well on Win Server

1 test:

setcookie("use","value"); // I can call cookie based on both win and
linux server

2 test:

setcookie("use","value",time()+3600); // I can call cookie based on win
only, But can't call cookie linux server

so, help me to fix this bug, Plz!

------------------------------------------------------------------------

[2002-03-08 00:00:04] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a month, 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".

------------------------------------------------------------------------

[2002-02-07 23:05:03] shiflett@php.net

Your code works for me, but I don't have a FreeBSD box to test on nor
an Internet Explorer browser.

However, let's not assume yet that this is a FreeBSD problem, since
that really seems unlikely with such a basic thing. The much more
probable case is that it is an IE bug, as IE has historically had
problems with adhering to HTTP standards specifically with cookies.

If your problem (as you say) is like the other bug you link to, then it
sounds like the problem lies in the browser not returning the cookie
rather than the cookie not being set.

To help investigate this, please check as many of the following things
as you know how:

1) HTTP response your PHP page generates
2) subsequent HTTP request from the browser (meaning, a request after
the cookie has been set)
3) Time (in GMT) on the browser
4) Time (in GMT) on the server
5) URL being used to access the page
6) Domain being used to set the cookie

If the problem doesn't reveal itself after inspecting these things, use
the header function as you did but with all hardcoded values to make
sure you're setting the cookie you think you are and that the date is
sufficiently far in the future to rule out any time synchronization
problems.

Thanks for your help!

Chris

------------------------------------------------------------------------

[2001-09-03 16:47:38] gotenforward at yahoo dot com

Another user experience the same problem like mine

http://www.php.net/bugs.php?id=11492&edit=1

It looks like they are all using FreeBSD

------------------------------------------------------------------------

[2001-09-03 16:33:11] gotenforward at yahoo dot com

I pretty much get the same error as this link

http://www.php.net/bugs.php?id=11478&edit=1

Over a couple hundreds of users, all of them works fine with IE 5.0+
However, some of the user can not login due to the cookie is not set.

Whenever I do

setcookie("username",$user,time()+3600,"/",".domain.com");

Some of the users using IE would not get the cookie.

But when i just change it to

setcookie("username",$user,"","/",".domain.com");

It works. But not setting expire time will not write the cookie to
harddisk, it just stored into memory, which is not what I want.

So, I tried to use the header function and see if that helps.

$time = mktime()+ $config[cookieTTL];
$date = gmdate("l, d-M-Y H:i:s", ($time));
header("Set-Cookie: $cookiename=$tmpstring; expires=$date GMT;
path=/;");

IE still do not pick up the cookie.


Here is a little function I use to store cookie

function putCookie($config,$cookiename, $varname, $data, $send="") {

// function to store cookie, use serialize() to bypass the limit of
using 20 cookies per domain.
// And make it easier to add new cookie later.

//keep this array always static so that when we get out of this
function, it still keep the variable.
static $tmpArray;

$tmpArray[$varname] = $data;

if ($send != "") {
$tmpstring = serialize($tmpArray);
$tmpstring = base64_encode($tmpstring);

$time = mktime()+ $config[cookieTTL];
$date = gmdate("l, d-M-Y H:i:s", ($time));

setCookie($cookiename, $tmpstring, "", $config[cookie_path],
$config[CookieURL]); // now we clean the static array after we send the
cookie

unset($tmpstring);
$tmpArray = "";
unset($tmpArray);
}
}

------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=13116&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666