Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/12830-local-time/
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.
Link to comment
https://forums.phpfreaks.com/topic/12830-local-time/#findComment-49311
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.
Link to comment
https://forums.phpfreaks.com/topic/12830-local-time/#findComment-49582
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.