php会话何时确切到期? [英] When exactly does a php session expire?

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

问题描述

我已经对此进行了搜索,到目前为止,我所知道的是,当浏览器关闭时,该会话会被破坏,如果只是保持浏览器处于打开状态,则该会话会在固定的时间(例如24分钟)后自动终止.

I've googled around about this and what I know so far is that the session is destroyed when the browser is closed and if the browser is just kept open, the session automatically expires after a fixed amount of time like 24 minutes.

但是这24分钟的计数器什么时候开始?服务器何时执行session_start()行?这个问题可能会有点长,但是请忍受我.假设我有一个php页面,其中包含以下代码:

But when does the counter for these 24 minutes start? When the server executes the session_start() line? This question might be a little long but please bear with me. Assume i have a php page with this code in it:

<?php
      session_start();
?>

如果用户打开此页面并将其保持打开状态约一个小时,那么即使该页面仍处于打开状态,会话是否仍会过期?并且,如果我在网站的每一页的开头添加session_start()代码,那么每次用户打开网站的新页面时,计数器是否会重置为零吗?

If a user open this page and just keeps it open for about an hour, will the session still expire although the page is still open? And if i add the session_start()code at the beginning of every page of my site, does the counter get reset to zero every time the user open a new page of the site?

基本上,我想创建一个登录系统,以便在用户关闭网站或单击注销"按钮时将其注销,并且只要他打开了网站,我就希望使他保持登录状态,而不会让他自动注销24分钟或任何其他固定时间之后.

Basically I want to make a login system that logs a user out when he closes the site or clicks the log out button and i want to keep him logged in as long as he has the site open, without him getting logged out automatically after 24 minutes or any other fixed time.

推荐答案

时间是在首次创建会话时开始的. 24分钟后,它可能会或可能不会被垃圾收集器擦除,因为它会随机插入(请参阅session.gc_ *指令). 您要做的是每N分钟重新生成一次会话(session_regenerate_id()),这样只要用户处于活动状态,会话就不会过期.

The timing starts when the session is first created. After the 24 minutes, it might or might not be erased by the garbage collector as it randomly kicks in(see session.gc_* directives). What you want to do is regenerate the session every N minutes(session_regenerate_id()), so that it doesn't expire as long as the user is active.

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

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