gpt4 book ai didi

php - 从 5 分钟前获取时间

转载 作者:行者123 更新时间:2023-11-29 02:53:23 26 4
gpt4 key购买 nike

我正在为我正在使用的 CMS 开发用户功能,并且我在每个页面加载时更新用户使用

if(User("online") == true) {
LastOnlineUpdate($_SESSION['key']['userid']);
}

(Yes User Online Works,这是我检查在线用户的功能)现在我的时间已正确更新 Hook 到 LastOnlineUpdate 函数然后运行我的类函数

    public function SessionUpdate($arg) {
$query = <<<SQL
UPDATE {$this->tprefix}online
SET remote = :remote, timestamp = :timestamp
WHERE userid = :arg
SQL;
$resource = $this->db->db->prepare( $query );
$resource->execute( array(
':remote' => $_SERVER['REMOTE_ADDR'],
':timestamp' => time(),
':arg' => $arg,
));
}

现在,每当我浏览我的页面时,它都会通过在我的预加载文件中包含第一个代码来更新用户,现在我遇到了我的障碍,尽管我从未做过一些事情,那就是占用我插入的时间表格,如果时间少于五分钟,请选择它并将其用于我的在线用户部分

public function OnlineUsers() {
$query = <<<SQL
SELECT userid
FROM {$this->tprefix}online
WHERE timestamp > time(5Minutes)
SQL;
$resource = $this->db->db->prepare( $query );
$resource->execute();
$this->onlinecount = $resource->rowCount();
if($resource->rowCount() == 0 ) {
$this->onlineusers = "No User's Online";
}
else
{
foreach($resource as $row) {
self::ConvertIDToName("displayname"); //Can be display, user, first or whatever else for the argument, The onlineusers variable is then set based off that query
}
}
}

最佳答案

$minutes = 5;
$date = gmdate('Y-m-d H:i:s'); // http://php.net/manual/en/function.gmdate.php
$date_plus_minutes = gmdate('Y-m-d H:i:s', ( time() + $minutes * 60 ) );
$date_minus_minutes = gmdate('Y-m-d H:i:s', ( time() - $minutes * 60 ) );

关于php - 从 5 分钟前获取时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33228592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com