PHP 检查用户是否在线

标签 php timestamp

谁能告诉我为什么这不起作用?在我的数据库中,lastactive2013-12-10 16:15:12,每次用户刷新我网站上的任何页面时都会更新。

我选择它并将其设置为变量:

$lastactive = $row[5]; 

这是我认为它应该工作的地方,但没有。使用 10 秒进行测试。

if(time() > $lastactive+10){
    print('<div id="user_online_status" style="color: #aaa;">[OFFLINE]</div>');
}
else if(time() < $lastactive+10){
    print('<div id="user_online_status">[ONLINE]</div>');
}

最佳答案

您正在将 unix 时间戳与 MySQL 日期时间字符串进行比较。在比较两者之前,您需要将其转换为 unix 时间戳:

$lastactive = strtotime($row[5]);

关于PHP 检查用户是否在线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504344/

相关文章:

php - Laravel:使用 Eloquent belongsto ,从两个表中获取数据?

php - 优化性能 : Many CURL requests

php - 为什么空事务会保留我的实体(学说)?

php - 选择多个数组元素

timestamp - 在 AutoHotkey 中获取毫秒数

mysql - SQL查询按时间戳的月份部分分组

php - 如何构建一个每个用户有 50 个变量的 MySQL 数据库?

date - UniVerse native 日期格式

java - 使用 Log4j2 2.11 的微秒级打印分辨率

python - Pyspark:时间戳的平均值