By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

server time vs browser time on cookie expirations

P: n/a
Say,

I want to set a cookie and have it expire an hour after it's set. It's
looking like this is only possible for browsers which are in the same time
zone as my server??

In other words, if I set my cookie with:

setcookie('CookieName', $SomeValue, time()+3600, "/");

the cookie should expire 1 hr later. But time() returns the time as it is at
the location of the server. If whoever loads my page is 3 timezones east of
where my server is, the time that I set is already expired as far as that
browser is concerned!

Is this correct or am I completely nuts?

If it is correct, is there any way I can set a cookie based on the browser
machine's time clock, so it will work the way I want no matter where the
browser is located relative to the server?

-dg
Jul 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cookies can be evil at times :)

Two facts:

1. The only legal timezone allowed for a cookie is GMT, no matter where
the server lives.
2. time() returns the number of seconds since 01/01/1970 00:00:00 GMT.

Now, I've not done any tests, but I belive that the browser itself will
determine what timezone it is in and will decide on whether to purge the
cookie -after- converting from GMT to its own timezone.

So, I believe that you're safe doing what you are doing and you
shouldn't worry about timezones.

Here's Netscape's cookies specification:
http://wp.netscape.com/newsref/std/cookie_spec.html

MK.

dan glenn wrote:
Say,

I want to set a cookie and have it expire an hour after it's set. It's
looking like this is only possible for browsers which are in the same time
zone as my server??

In other words, if I set my cookie with:

setcookie('CookieName', $SomeValue, time()+3600, "/");

the cookie should expire 1 hr later. But time() returns the time as it is at
the location of the server. If whoever loads my page is 3 timezones east of
where my server is, the time that I set is already expired as far as that
browser is concerned!

Is this correct or am I completely nuts?

If it is correct, is there any way I can set a cookie based on the browser
machine's time clock, so it will work the way I want no matter where the
browser is located relative to the server?

-dg


--
MeerKat

Jul 16 '05 #2

P: n/a
Oh, and I forgot to add that this assumes that the client has their
clock set correctly and set to the correct timezone...

MeerKat wrote:
Cookies can be evil at times :)

Two facts:

1. The only legal timezone allowed for a cookie is GMT, no matter where
the server lives.
2. time() returns the number of seconds since 01/01/1970 00:00:00 GMT.

Now, I've not done any tests, but I belive that the browser itself will
determine what timezone it is in and will decide on whether to purge the
cookie -after- converting from GMT to its own timezone.

So, I believe that you're safe doing what you are doing and you
shouldn't worry about timezones.

Here's Netscape's cookies specification:
http://wp.netscape.com/newsref/std/cookie_spec.html

MK.

dan glenn wrote:
Say,

I want to set a cookie and have it expire an hour after it's set. It's
looking like this is only possible for browsers which are in the same
time
zone as my server??

In other words, if I set my cookie with:

setcookie('CookieName', $SomeValue, time()+3600, "/");

the cookie should expire 1 hr later. But time() returns the time as it
is at
the location of the server. If whoever loads my page is 3 timezones
east of
where my server is, the time that I set is already expired as far as that
browser is concerned!

Is this correct or am I completely nuts?

If it is correct, is there any way I can set a cookie based on the
browser
machine's time clock, so it will work the way I want no matter where the
browser is located relative to the server?

-dg


--
MeerKat

Jul 16 '05 #3

P: n/a
MeerKat - If what you say is true (that time() returns a GMS timestamp and
not a timestamp that is the servers own timezone time), then it must follow
that the date() function must do an automatic timezone conversion to local
time. For when I do an

echo date("l dS of F Y h:i:s A",time());

on my localhost, I get exactly my current local timezone time, NOT GMT. But
I don't see any mention of this auto-conversion to local time zone
functionality in the DATE() function documentation.

Certainly time() DOES return the GMS timestamp - I don't doubt that. It's
just that I've been using examples of the above on my localhost and 3-hr
different timezone server and had it firmly in my mind that time() was
reporting local server time because those were the times I was getting,
under the date() transformation.

My php manual states, under date():

Returns a string formatted according to the given format string using the
given integer timestamp or the current local time if no timestamp is given.

The phrase "or the current local time if no timestamp is given" implies to
me that when a timestamp IS given, it would just report the GMS time, since
that's what a 'real' timestamp is. But it doesn't, evidently. It takes a GMS
timestamp and reports local time. Is this your understanding?

thanks,
dg

"MeerKat" <li****************@blueyonder.co.uk> wrote in message
news:KA*****************@news-binary.blueyonder.co.uk...
Cookies can be evil at times :)

Two facts:

1. The only legal timezone allowed for a cookie is GMT, no matter where
the server lives.
2. time() returns the number of seconds since 01/01/1970 00:00:00 GMT.

Now, I've not done any tests, but I belive that the browser itself will
determine what timezone it is in and will decide on whether to purge the
cookie -after- converting from GMT to its own timezone.

So, I believe that you're safe doing what you are doing and you
shouldn't worry about timezones.

Here's Netscape's cookies specification:
http://wp.netscape.com/newsref/std/cookie_spec.html

MK.

dan glenn wrote:
Say,

I want to set a cookie and have it expire an hour after it's set. It's
looking like this is only possible for browsers which are in the same time zone as my server??

In other words, if I set my cookie with:

setcookie('CookieName', $SomeValue, time()+3600, "/");

the cookie should expire 1 hr later. But time() returns the time as it is at the location of the server. If whoever loads my page is 3 timezones east of where my server is, the time that I set is already expired as far as that browser is concerned!

Is this correct or am I completely nuts?

If it is correct, is there any way I can set a cookie based on the browser machine's time clock, so it will work the way I want no matter where the
browser is located relative to the server?

-dg


--
MeerKat

Jul 16 '05 #4

P: n/a
On Sat, 09 Aug 2003 15:49:40 -0500, in message
<E7***************@newssvr25.news.prodigy.com>,"da n glenn"
<da********@yahoo.com> wrote:
I want to set a cookie and have it expire an hour after it's set.
[...] But time() returns the time as it
is at the location of the server. If whoever loads my page is 3
timezones east of where my server is, the time that I set is already
expired as far as that browser is concerned!


It's not a problem because the cookie's expire
time is sent as text, not a unix time value,
and the cookie is in GMT, for example:

HTTP/1.1 200 OK
Date: Sun, 10 Aug 2003 01:41:51 GMT
Set-Cookie: cookie[one]=cookieone; expires=Sun, 10-Aug-03 01:51:51 GMT
Connection: close
Content-Type: text/html
Content-Language: en

Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.