imgrooot Posted March 25, 2017 Share Posted March 25, 2017 (edited) I was wondering if there is a way to automatically get a user's timezone? I want to show certain information if the user's current date is less than the expiry date. It works fine if the user is in a default timezone but what if the user is in a different timezone? How I can I make sure I can get their correct current time? date_default_timezone_set('America/New_York'); $expiry_date = trim($row['expiry_date']); $current_date = date('Y-m-d H:i:s'); if($current_date < $expiry_date) { // show data } else { // don't show } Edited March 25, 2017 by imgrooot Quote Link to comment https://forums.phpfreaks.com/topic/303534-is-there-a-way-to-get-users-timezone-using-php/ Share on other sites More sharing options...
Solution Jacques1 Posted March 25, 2017 Solution Share Posted March 25, 2017 (edited) No, there is no way to get the client's timezone with PHP. As you probably know, PHP runs on the server, and the HTTP requests sent by the clients don't contain any timezone information. What you can do is try to get the timezone with JavaScript or make the user explicitly select their timezone. You can also use the IP address and a geolocation database to make an educated guess (but you still need a way for the user to correct the information). Edited March 25, 2017 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/303534-is-there-a-way-to-get-users-timezone-using-php/#findComment-1544563 Share on other sites More sharing options...
imgrooot Posted March 25, 2017 Author Share Posted March 25, 2017 No, there is no way to get the client's timezone with PHP. As you probably know, PHP runs on the server, and the HTTP requests sent by the clients don't contain any timezone information. What you can do is try to get the timezone with JavaScript or make the user explicitly select their timezone. You can also use the IP address and a geolocation database to make an educated guess (but you still need a way for the user to correct the information). Got it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/303534-is-there-a-way-to-get-users-timezone-using-php/#findComment-1544564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.