deleting cookies and local browser time versus server time

deleting cookies and local browser time versus server time

am 02.01.2008 18:05:08 von Law Poop

Hello all -

Is there a way to get the local time from the user's browser? I didn't
see anything in the $_SERVER array.

For unsetting cookies, the PHP documentation page for cookies
recommends setting the expiration date to a point in the past.
However, I'm running into problems with time conflicts. Our server is
in a different time zone than the browser I'm developing on. I would
like to go in five-minute increments to test my code after the cookie
expires, and it took me forever to figure out why my cookies weren't
expiring in five minutes.

It's not a big deal because it's only a few hours, so I can set the
time back several hours when we actually go into production. Of
course, hard coding any time could fail, is the user is halfway around
the world. So ideally I could look at the browser's local time, and
set the cookie back appropriately.

Re: deleting cookies and local browser time versus server time

am 02.01.2008 19:11:23 von Good Man

lawpoop@gmail.com wrote in news:0ba47cb1-6fbe-44ae-b328-b4415bf387b1
@d21g2000prf.googlegroups.com:

> Hello all -
>
> Is there a way to get the local time from the user's browser? I didn't
> see anything in the $_SERVER array.

Well, considering you're asking the $_SERVER for a local user variable,
it won't be there.

That should also raise a flag for you - since PHP is parsed on the
server, you in fact have no way of determining your user's local time
using PHP.


> For unsetting cookies, the PHP documentation page for cookies
> recommends setting the expiration date to a point in the past.
> However, I'm running into problems with time conflicts. Our server is
> in a different time zone than the browser I'm developing on. I would
> like to go in five-minute increments to test my code after the cookie
> expires, and it took me forever to figure out why my cookies weren't
> expiring in five minutes.

Don't involve the user local time at all. Put the server time in a
variable, and test THAT number in 5 minute increments.


> It's not a big deal because it's only a few hours, so I can set the
> time back several hours when we actually go into production. Of
> course, hard coding any time could fail, is the user is halfway around
> the world. So ideally I could look at the browser's local time, and
> set the cookie back appropriately.

Again, PHP knows nothing about the browser client.

Re: deleting cookies and local browser time versus server time

am 02.01.2008 20:11:06 von Law Poop

On Jan 2, 12:11 pm, Good Man wrote:
> lawp...@gmail.com wrote in news:0ba47cb1-6fbe-44ae-b328-b4415bf387b1
> @d21g2000prf.googlegroups.com:
>
> > Hello all -
>
> > Is there a way to get the local time from the user's browser? I didn't
> > see anything in the $_SERVER array.
>
> Well, considering you're asking the $_SERVER for a local user variable,
> it won't be there.

$_SERVER does seem to contain some values that come from the browser:

$_SERVER[REQUEST_METHOD] => GET

Or did the server decide whether the browser was GETting or POSTing ?

$_SERVER[REDIRECT_QUERY_STRING] => query_string_test=hello

Or did the server somehow put the string variables in the browser's
address bar?

Several others are listed in this page:

http://us.php.net/reserved.variables

>
> That should also raise a flag for you - since PHP is parsed on the
> server, you in fact have no way of determining your user's local time
> using PHP.

Well, if I can know what page the user is requesting, what variables
they're sending, or what browser they're claiming to use, I don't see
any *theoretical* reason the browser couldn't also send a timestamp or
a timezone. Whether or not they do, and if I can get access to that
information from PHP, is what I'm trying to figure out.

>
> > For unsetting cookies, the PHP documentation page for cookies
> > recommends setting the expiration date to a point in the past.
> > However, I'm running into problems with time conflicts. Our server is
> > in a different time zone than the browser I'm developing on. I would
> > like to go in five-minute increments to test my code after the cookie
> > expires, and it took me forever to figure out why my cookies weren't
> > expiring in five minutes.
>
> Don't involve the user local time at all. Put the server time in a
> variable, and test THAT number in 5 minute increments.
>

How can I test cookie expiration with that? The browser unsets cookies
based on what *it* thinks the time is, not what the server thinks the
time is.

In other words, if the server is in Pacific time, and I'm in Eastern
time, setting the cookie to expire on date() ( meaning, 'right now' )
looks to be 3 or 4 hours in the past to my browser. So, if the server
give a cookie to expire at 4PM today, which is the time in Seattle,
that expiration date is already in the past for me, since it's already
7PM.

To work around this, I might add 3 hours while I'm in development, but
then what about people in Mountain or Central time once I'm in
production? I can hard code a number of hours, since I know the
difference between my timezone and the server's. Obviously I can't
assume a future user's timezone. It would be handy is the user's
browser told me their time or time zone.

> Again, PHP knows nothing about the browser client.

It knows what the browser claims to be:

$_SERVER[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0;
en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

Or did the server decide this also?

Re: deleting cookies and local browser time versus server time

am 02.01.2008 23:34:14 von Good Man

lawpoop@gmail.com wrote in
news:43ae8e36-b358-4a34-9b2f-699797bb0bba@l6g2000prm.googleg roups.com:

> Several others are listed in this page:
>
> http://us.php.net/reserved.variables

Yep, my bad. I guess I just tend to ignore any 'browser' information in
my apps.


>> > For unsetting cookies, the PHP documentation page for cookies
>> > recommends setting the expiration date to a point in the past.
>> > However, I'm running into problems with time conflicts. Our server
>> > is in a different time zone than the browser I'm developing on. I
>> > would like to go in five-minute increments to test my code after
>> > the cookie expires, and it took me forever to figure out why my
>> > cookies weren't expiring in five minutes.
>>
>> Don't involve the user local time at all. Put the server time in a
>> variable, and test THAT number in 5 minute increments.
>>
>
> How can I test cookie expiration with that? The browser unsets cookies
> based on what *it* thinks the time is, not what the server thinks the
> time is.
>
> In other words, if the server is in Pacific time, and I'm in Eastern
> time, setting the cookie to expire on date() ( meaning, 'right now' )
> looks to be 3 or 4 hours in the past to my browser. So, if the server
> give a cookie to expire at 4PM today, which is the time in Seattle,
> that expiration date is already in the past for me, since it's already
> 7PM.

I guess I'm having a bit of difficulty trying to understand. Cookies
are local/stored on the user browser, correct? So with you in Los
Angeles and I in New York, we'll never see each others' cookies.

I interpreted your problem as essentially keeping a file 'open' or
'checked out' (insert your verb here) for 5 minutes before
allowing/disallowing changes or something. So, if you open a file at
10amPST, and I want to open it a minute later (1pm EST), I should see
that only 1 minute has passed (as opposed to 3 hours and 1 minute).

If that's the case, what I am suggesting is that when person A opens the
document, you record the SERVER time in a database or text file. Then
when person B hits the same document, PHP compares the time elapsed on
the server between when Person A and Person B accessed the document, ie:
whether or not its been less than / greater than 5 minutes.

Sorry to be of so little help!

Re: deleting cookies and local browser time versus server time

am 03.01.2008 16:36:24 von Law Poop

On Jan 2, 4:34 pm, Good Man wrote:

> > How can I test cookie expiration with that? The browser unsets cookies
> > based on what *it* thinks the time is, not what the server thinks the
> > time is.
>
> > In other words, if the server is in Pacific time, and I'm in Eastern
> > time, setting the cookie to expire on date() ( meaning, 'right now' )
> > looks to be 3 or 4 hours in the past to my browser. So, if the server
> > give a cookie to expire at 4PM today, which is the time in Seattle,
> > that expiration date is already in the past for me, since it's already
> > 7PM.
>
> I guess I'm having a bit of difficulty trying to understand. Cookies
> are local/stored on the user browser, correct? So with you in Los
> Angeles and I in New York, we'll never see each others' cookies.

Perhaps I'm not understanding it properly myself. Let me try to
explain it.

The website gives a cookie to the browser. That cookie stores
information that applies only to that website. It's like asking the
browser to store information for the website, and return that
information when the browser returns to that website.

One of the properties of the cookie is that it has an expiry time. It
won't last forever; the time that it lasts is set by the website.
Since the expiry time may pass when the user is not browsing the site,
it's up to the browser to delete a cookie when it has expired. This
cookie deletion happens independently of the wesbite; the browser does
it on its own.

If we are two browsers looking at the same site, we won't see each
others cookies. You are correct there. However, if we are browsing the
same site, we will each have our own cookies that we each get from the
website.

However, when a user returns to a website, the website can see the
cookie(s) that it previously gave a browser, so long as they haven't
expired. If they have expired, the browser won't send them back to the
website. And therein lies the rub: if the browser and the server
disagree about what time it is, the server may be expecting the cookie
when the browser thinks it's too old.

So, if the server generates a cookie that is set to expire at
something like "date() + 5 minutes", a timezone change could trip that
up. For the server in California, the time may be 8 AM, so it gives
the cookie to the browser, with an expiration time of 8:05 AM. For the
browser in New York, it's already 11 AM ( if it's 8 AM in CA ) , so a
cookie set to expire at 8:05AM, the cookie is DOA.

It's like I'm in Portland and you're in New York. I want some
information from you, to get to the bank before 5 PM. For you, 5 PM
comes and goes, no information. Then, at 7PM New York time, you get
the information. You say, "Oh, it's past 5PM, it's too late."
Meanwhile in Portland, the local time is 4PM, because of the time zone
difference. You could call me and give me the information, but because
of the time zone difference, you and I disagree about what time it
is.

>
> I interpreted your problem as essentially keeping a file 'open' or
> 'checked out' (insert your verb here) for 5 minutes before
> allowing/disallowing changes or something. So, if you open a file at
> 10amPST, and I want to open it a minute later (1pm EST), I should see
> that only 1 minute has passed (as opposed to 3 hours and 1 minute).
>
> If that's the case, what I am suggesting is that when person A opens the
> document, you record the SERVER time in a database or text file. Then
> when person B hits the same document, PHP compares the time elapsed on
> the server between when Person A and Person B accessed the document, ie:
> whether or not its been less than / greater than 5 minutes.

Actually that's a great idea. Instead of storing data in the cookie, I
can just store a unique token in it to identify returning users. I can
use that token to look up the actual data I want to store from the
database.

>
> Sorry to be of so little help!

Well, it is helpful to discuss it with someone. If I can't explain my
situation properly, that probably means I don't understand it myself!