How to pass a javascript variable to PHP without using $_GET? How to pass a javascript variable to PHP without using $_GET? json json

How to pass a javascript variable to PHP without using $_GET?


If you don't want to use a GET request, you could consider using a POST request instead. You can send the data from with an Ajax request in JavaScript. Using jQuery, this would look something like:

$.ajax({   'url': 'PATH_TO_PHP_SCRIPT',   'type': 'POST',   'data': 'timezone=' + timezoneVariable});


If you don't want to use JSON and ajax(XMLHttpRequest), you can use cookies. Since both javascript and php can read these, create one using javascript to store the timezone . Then in your php code read that cookie.

to create a cookie in javascript use :

document.cookie =     'myName=' + value +     '; expires=' + now.toGMTString() +     '; path=/';

and to read it in your php :

$_COOKIE['myName']


You can simply GET/POST an URL like /tz/TIME_ZONE where TIME_ZONE is whatever timezone you want to set.