0

Guys,

please let me know is anybody aware of the below doubt.

php taking hosting server date and time but am in need to find the client time and date who accesing the site.

otherwise how to find the date & time in server time zone .

5
Contributors
7
Replies
31
Views
4 Years
Discussion Span
Last Post by eburlea
0

The simple solution is to ask visitors what timezone they're in and calculate the date from the offset. A less simple solution is to use Javascript/AJAX to acquire the date-time from the client side and pass it to the server for processing.

0

PHP doesn't know the date and time of the client machine, since it is run on server. Use javascript to get the client's datetime and push it into the database through an AJAX call

0

Hello!

I have the same problem and I have solved just half of it.

I have downloaded a javascript plugin 'jsTimezoneDetect' (https://bitbucket.org/pellepim/jstimezonedetect/downloads) and linked it in the header. Then I wrote the following code that is returning the timezone:

<script type="text/javascript">
    var timezone = jstz.determine();
    var user_timezone = timezone.name();
</script>

How can I pass the value of the variable user_timezone to PHP in the same page? I do not want to use method $_GET. I have tried with Ajax, but without success.

I am using Zend Framework and I need to pass the value from View to Controller.

Thanks.

0

After hours of googling, I have found the answer on http://www.satya-weblog.com/2007/05/php-and-javascript-cookie.html

in View

<script type="text/javascript">
    var timezone = jstz.determine();
    document.cookie = 'user_timezone=' + timezone.name();
</script>

in Controller

$request = new Zend_Controller_Request_Http();
$user_timezone = $request->getCookie('user_timezone');
if(isset($user_timezone)){
    echo 'User Timezone is ' . $user_timezone . '.';
} else {
    echo 'The cookie has not been set yet.';
}
0

Yes, it is working.

Actually I make some settings in Bootstrap for language, timezone, etc. The javascript code for getting user timezone I put in Layout. With the codes above I am able to catch the cookie value set with javascript and use in PHP.

But if there are better solutions, I would like to know them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.