设置会话到期时间 [英] Set session expiry time

查看:67
本文介绍了设置会话到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整个网站的会话到期时间设置为 10 分钟?我不能在共享主机上使用 php.ini.

How can I set the session expiry time to 10 minutes for the whole of my site? I cannot use the php.ini as its on shared hosting.

有我可以使用的全局方法吗?

Is there a global method I could use?

推荐答案

我不这么认为.

您可以将网站上次刷新的时间戳保存到会话中,并在下次重新加载时将其与当前时间进行比较.

You can save the timestamp of the last refresh of your website into a session and compare it with the current time on the next reload.

if(isset($_SESSION['expiretime'])) {
    if($_SESSION['expiretime'] < time()) {
        //logged out
    }
    else {
        $_SESSION['expiretime'] = time() + 600;
    }
}
//maybe add some login procedures and than execute the following line
$_SESSION['expiretime'] = time() + 600;

这篇关于设置会话到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆