NYCPHP Meetup

NYPHP.org

[nycphp-talk] Getting GMT bias from browser

Billy Reisinger billy.reisinger at gmail.com
Mon Oct 9 11:50:41 EDT 2006


Yeah, there's no good way to do this other than to have the user's  
browser tell you what it thinks the date/time is.  The Javascript Date 
() object will, by default, return a date string that has the GMT  
offset in it.

Mon Oct 09 2006 10:32:00 GMT-0500 (CDT)

It also has a method called getTimezoneOffset(), which tells you the  
(+/-) minutes away from GMT the browser is.  You could just test the  
value of $_COOKIE in php, redirect to a page that sets a cookie, and  
then go back to the main page.  It sucks, but it works.
<?php
	if(empty($_COOKIE)) {
?>
	<script type="text/javascript">
	var Cookies = {};
	/***
	* @name = string, name of cookie
	* @value = string, value of cookie
	* @days = int, number of days before cookie expires
	***/
	Cookies.create = function (name, value, days) {
	    if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	    } else {
		var expires = "";
	    }
	    document.cookie = name + "=" + value + expires + "; path=/";
	    this[name] = value;
	}
	var now = new Date();
	Cookies.create("GMT_bias",now.getTimezoneOffset(),7);
	window.location = "<?php echo $_SERVER['PHP_SELF'];?>";
	</script>
<?php
} else {
	echo "<pre>";
	print_r($_COOKIE);
	echo "</pre>";
}
?>


Hope that speeds things up for you.
Billy



On Oct 6, 2006, at 10:03 PM, Paul Reinheimer wrote:

> This isn't going to appear in any of the headers the browser is going
> to send you, here's my print_r on apache_get_headers()
> --
> Array
> (
>     [User-Agent] => Opera/9.01 (Macintosh; Intel Mac OS X; U; en)
>     [Host] => example.preinheimer.com
>     [Accept] => text/html, application/xml;q=0.9,
> application/xhtml+xml, image/png, image/jpeg, image/gif,
> image/x-xbitmap, */*;q=0.1
>     [Accept-Language] =>
> en,ja;q=0.9,fr;q=0.8,de;q=0.7,es;q=0.6,it;q=0.5,nl;q=0.4,sv;q=0.3,nb;q 
> =0.2
>     [Accept-Charset] => iso-8859-1, utf-8, utf-16, *;q=0.1
>     [Accept-Encoding] => deflate, gzip, x-gzip, identity, *;q=0
>     [Cookie] => ZDEDebuggerPresent=php,phtml,php3
>     [Cookie2] => $Version=1
>     [Connection] => Keep-Alive, TE
>     [TE] => deflate, gzip, chunked, identity, trailers
> )
> --
>
> Nothing in there about the GMT bias.
>
> I think your javascript idea however could be put to a decent use, use
> javascript to request a document, write a link to an image or whatever
> and send the user's current time that way. then store the information
> in a cookie, or their session.
>
>
> paul
>
> -- 
> Paul Reinheimer
> Zend Over Certified Engineer 4^2, 5^2 :)
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php




More information about the talk mailing list