|
Posted by lawpoop on 01/02/08 19:11
On Jan 2, 12:11 pm, Good Man <he...@letsgo.com> 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?
Navigation:
[Reply to this message]
|