Trouble With Database and PHP Time

Status
Not open for further replies.

rforum

New Member
Messages
8
Reaction score
0
Points
0
I’m having problems with time on my hosting account.

While I’m checking the session time from a database table, then comparing it to time(), the time is an hour off.

First I save the time to the database with SET `session_time` = FROM_UNIXTIME(".time()."). (I also tried SET `session_time` = NOW() )
Later in the same script, I recall the saved value from the database and compare it to time() to check how long the user has been inactive.
The times are an hour off even though I saved and recalled the time in the same execution of the script! I know the script works because I test it on another sever before putting it on x10.

I have had the times change on me twice so far. The first time, about a week ago, the time difference was an hour off. It was back to normal when I checked again the next day. The second time started about three hours ago, and is still an hour apart. My sever name is Lotus.x10 and my domain name is rforum.x10hosting.com. Help?

Part of the function:

PHP:
$check = getuser($iuser); #('SELECT * FROM `user` WHERE `user_id` = \''.$iuser.'\' LIMIT 1';)
$timelast = strtotime($check['session_time']);
$timenow = time();
echo '<BR>Time diff:'.($timenow - $timelast); #(=3600)
 
if ($timelast != $timenow){
$query = "UPDATE `user` SET `session_time` = FROM_UNIXTIME(".time()."), `session_ip` = '$ipnow' WHERE `user_id` = '$iuser'";
}
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
I just verified the times, they look to be correct...
 

rforum

New Member
Messages
8
Reaction score
0
Points
0
Run this time script on rforum.x10hosting.com.

PHP:
PHP:
$dbtime = strtotime(mysql_result(mysql_query("SELECT NOW()"),0));
$phptime = time();
echo "MYSQL time: $dbtime";
echo "<BR>PHP time: $phptime";

The result I'm getting is:
MYSQL time: 1219631462
PHP time: 1219635062
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
The date.timezone configuration directive for PHP is set to America/New_York, which is EST (or GMT-5).

The server is set to CDT (or GMT-6), so that is the cause between the differences.

A possible reason behind the variation over the last few days may have been caused by the inconsistency with the PHP versions configuration files, they've been changed around a lot the last few days.

I've discussed it with Corey and we're going to be moving all servers' times up to EST. They're all currently in CDT now. This will probably happen sometime within the next few hours.
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
I just want to let you know I've made the time change on all of our free servers. If you have this issue again, let us know.
 
Status
Not open for further replies.
Top