Jump to content

Archived

This topic is now archived and is closed to further replies.

seidanis

Local time

Recommended Posts

Hello,

my JS knowledge is close to none, so please bare with me.
Finding out the visitor's time zone offset was not that hard:

[code]
var now = new Date();
var tzo = now.getTimezoneOffset();
[/code]

What I need to do now, is automatically pass "tzo" back to the server, for further processing via PHP. Passing its value onto a PHP variable would be ideal.

Any hints please?

Alex

Share this post


Link to post
Share on other sites
well if you are having the user fill out a form you could just pass the var through the form in a hidden field, and retrieve it in php via $_GET['tzo'] or POST['tzo'] (whichever form method you use).

or, you could use ajax to send it in the background, and you would still retrieve it in php the same way.

Share this post


Link to post
Share on other sites
There are three basic ways of sending variables to PHP from javascript.

You can put them into a cookie which can then be read back by PHP, but only works if the user has cookies enabled.

You can put them in a form which the PHP script will get in the $_POST or $_GET array.

You can request a script from the server with the variables added as query parameters. This last one could be done in two ways. You either redirect the browser to that script, or you request it as if it were a file such as an image, but instead of trying to load say "dummy.jpg" or "dummy.png" you request "dummy.php?param=whatever". As long as it has query parameters it will not be cached and therefore will be run each time. The script would have to output a dummy image to send back to the browser, but there is nothing to stop it doing other work as long as it doesn't try to generate any HTML.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.