Jump to content


Photo

Local time


  • Please log in to reply
2 replies to this topic

#1 seidanis

seidanis
  • Members
  • Pip
  • Newbie
  • 4 posts
  • LocationAthens, Greece

Posted 24 June 2006 - 10:55 PM

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:

var now = new Date();
var tzo = now.getTimezoneOffset();

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
Alex Seidanis

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 June 2006 - 07:19 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 26 June 2006 - 09:02 AM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users