This answer is based on the assumption that you are using a web page to display the user's time zone.
First of all, you cannot get the user's timezone in PHP. But what you can do is tell the server that the user date is via JavaScript.
You can do something like this:
var currentdate = new Date(); if(currentdate.getMonth() === 11){ // note that January = 0, Feb = 1 etc. So December = 11 $.get( "//christmasServer.com/timezone.php?user_day=" + currentdate.getDate(), function( data ) { // send to server, getDate() will show the day, December 14 will just show 14 $('.Christmas').html( data ); // do something with the data, for example replace the div .Christmas }); } else { // It not even december in your timezone :-o }
In timezone.php you can now determine what day is.
As a supplement:
You can set the time zone in $_SESSION so that you can set it only once.
timezone.php:
if(!isset($_SESSION['user_timezone'])){ // if timezone isn't set session_start(); // start session $_SESSION['user_timezone'] = $_GET['user_day']; } if($_SESSION['user_timezone']===1){ // if it the first of December echo 'I\'m shown December first'; } else if($_SESSION['user_timezone']===2){ // if it the second of December echo 'I\'m shown December second'; } // etc...
Now you can use $_SESSION['user_timezone'] to get the time zone of users.
source share