I am having huge issues with php time.
For some reason it shows a different time (by 2 hours) to some users and the correct time to other users.
The code is H:i:s d-M-y T when I view the page in a browser from my PC it tells me its 11am when infact its 9am, when I check via a browser using one my RDP's I get the correct time.
Both PC's are in the country (uk) both PC's have the same system time etc.
Tried setting the timezone default, but no matter what I do the server still shows some users the correct time, and other users the time 2 hour forward, any ideas?
the code is echo gmdate("H:i:s d-M-y T");
<?php echo gmdate("H:i:s d-M-y T"); ?>
As a work around, let me explain this: There are users who get the right time, others get -2h. If we log the last time in a file, and next time a user opens the page, we check if $now is smaller than $last_time, if it is, we add 2 hours ! Let me explain this with numbers, User1 visited the page, and it returns the right hour, let's say 11AM. User2 opens the page, and it return 9AM, obviously we can't return in the time, so we add 2 hours !
Here the code:
<?php
$last_time = file_get_contents("file.txt"); // a file where the last time has been saved
$now = strtotime(gmdate("H:i:s d-M-y T")); // Now !
if($now < $last_time){
$now += 7200; // add 2 hours !
}
file_put_contents("file.txt", $now);
echo gmdate("H:i:s d-M-y T", $now);
?>
Hope this was helpful !