会话超时修复

Session Timeout fix

我创建了一种输入答案的考试站点,为了找出答案,必须登录的打开的考试页面可以闲置一段时间。

我尝试实施这行代码以将会话超时长度增加到一个小时:

ini_set('session.gc_maxlifetime', 3600);

尽管我认为它对我没有用。是否必须在我有代码的每个页面上完成此操作:

session_start()

此外,确保登录会话保持打开的约定是什么,直到: - 标签关闭 - window 关闭 - 注销按钮按下 - 在地址栏中输入新的 URL ?

Does this have to be done on each page

是的。正如 PHP manual for ini_set 所述:

The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.


或者,您可以 "ping" 您的服务器每分钟保持会话活动(例如从 ajax 请求到简单的 PHP 脚本(像 <?php session_start(); ?> 就足够了)),或者您可以通过数据库等媒介自己控制会话。 Chris Shiflett has a good blog post on this.