PHP会话超时 [英] PHP Session timeout
本文介绍了PHP会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户登录时,我正在创建会话:
I am creating a session when a user logs in like so:
$_SESSION['id'] = $id;
如何在X分钟的会话上指定超时,然后在达到X分钟后让它执行功能或页面重定向?
How can I specify a timeout on that session of X minutes and then have it perform a function or a page redirect once it has reached X minutes??
我忘了提到由于会话不活跃,我需要会话超时.
I forgot to mention that I need the session to timeout due to inactivity.
推荐答案
首先,存储用户最后一次发出请求的时间
first, store the last time the user made a request
<?php
$_SESSION['timeout'] = time();
?>
在后续请求中,检查他们多久前一次提出请求(在此示例中为10分钟)
in subsequent request, check how long ago they made their previous request (10 minutes in this example)
<?php
if ($_SESSION['timeout'] + 10 * 60 < time()) {
// session timed out
} else {
// session ok
}
?>
这篇关于PHP会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文