I'm using JavaScript to get the user timezone name. I want that timezone name into PHP session variable in the same page. JavaScript is client side and PHP is server side. How will it be possible? Are there any ways to this?
Asked
Active
Viewed 127 times
0
-
1Use JS to create a session variable? And check for that using PHP? – evolutionxbox Feb 23 '17 at 13:04
-
to achieve that, i have tried with ajax request to same page... but this is not a good practice right? @Mohammad – Ratna Raju Feb 23 '17 at 13:04
-
2You might consider moving this timezone information between browser and Server using a cookie – RiggsFolly Feb 23 '17 at 13:05
-
1@RatnaRaju that'd be the only way to pass a javascript variable into php, since like you said, javascript is client-side an php is server-side. Check [this](http://stackoverflow.com/questions/4746249/get-user-timezone) answer. – Condorcho Feb 23 '17 at 14:36
1 Answers
0
You could make an ajax post and post the value you want to a php file and there update the php session variable like
$_SESSION['timezone'] = $_POST['timezone']

Stavros Angelis
- 962
- 5
- 8