Jump to content

Timestamp Always Starts at 3600


gaza165

Recommended Posts

Hi all,

 

can someone tell me whenever i update my users timestamp on the server it always starts at 3600 but locally it always starts at 0. this is the code im running...

 

user_online.php

 

<?php
session_start();
include("dbconnect.php");

$sql = mysql_query("SELECT last_activity,username FROM users");

echo "<ul class='online'>";
while($row = mysql_fetch_assoc($sql)) {

$usertime = strtotime($row['last_activity']);

$difference = time() - $usertime;
$idletime = 300; //3 Minutes

echo $difference." is the difference<br/>";
echo $idletime." is the idletime<br/><br/>";

if($difference > 600)
{
echo $row['username']." is offline<br/>";
} else

if($difference > 150)
{
$idletime++;
echo $row['username']." is idle<br/>";
} else {

echo $row['username']." is online<br/>";
}

}


?>

 

update.php

 

<?php
session_start();

include('dbconnect.php');
$username = $_SESSION['login']['username'];
$sql = mysql_query("UPDATE users set last_activity = CURRENT_TIMESTAMP  WHERE username = '$username'");

?>

Link to comment
https://forums.phpfreaks.com/topic/154180-timestamp-always-starts-at-3600/
Share on other sites

It's all done using MySQL and PHP, since there all server script side they can't be any difference comming from local time.

 

Some place you are using MySQL time other you use PHP time. My best guess is the MySQL and PHP aren't located on the same server. Usually PHP and MySQL server are physically near and they probably are in the same timezone. Maybe one of them is still on the daylight the other one not.

 

Try that or use similar in a temporary table :

 

<?php
include('dbconnect.php');
$results = mysql_query("UPDATE users set last_activity = CURRENT_TIMESTAMP  WHERE id=0;");

$results = mysql_query("SELECT last_activity FROM users WHERE id=0;");
$row = mysql_fetch_assoc($results);
$usertime = $row['last_activity'];

echo time()."<br>";
echo $usertime."<br>";

?>

 

If time() and $usertime are the same (maybe 1 or 2 seconds difference for the execution time),  you will know what the server time is for MySQL and PHP.

 

If both server should have same time and they haven't, contact your webhosting.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.