473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

server time vs browser time on cookie expirations

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
4 11640
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nigo | last post by:
Hi there Is it posible to make a link (to a php-file on a server) in an email that, when you click on it, sends info about who the reciver of the email is? Lets say I send out an email thru...
6
by: Rob Meade | last post by:
Hi all, At work we have 2 servers in a cluster for our web apps. One problem we have experienced (along with many others!) - is that if a user is logged into one of the applications on server...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
0
by: Bill Borg | last post by:
Hello all, I've read through the posts out here, mostly get it, but am still trying to understand the relationship among the ticket, the cookie, and their expirations. I understand that the...
6
by: Andre Ranieri | last post by:
I'm trying to create a login page for customers to log into our corporate website, our presidents naturally wants the user and password fields to populate from a cookie so the customer doesn't have...
2
by: junOnline | last post by:
Hi, I am developing an asp.net 2.0 application using visual studio 2005 on my computer and I am getting very inconsistent results when I test on my computer versus from other computers. The...
2
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
6
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not...
4
by: rodmc | last post by:
Hi, I am trying to set a cookie on a client computer using the Cookie module however all I get is the text being printed in the browser window. Can anyone point me in the right direction so that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.