[英]Which apache2/php5 config should I change if I don't want the session to die?
I'm logging my admin like this: 我正在这样记录我的管理员:
session_start();
$_SESSION['admin'] = TRUE;
When I login and stay inactive for like 10 minutes, then refresh, the session is dead and the admin is logged out. 当我登录并保持闲置状态约10分钟,然后刷新时,该会话已死,并且管理员已注销。
What do I need to set either in htaccess
or in the php file
itself so that the session stays alive for at least 8 hours? 我需要在
htaccess
或php file
本身中进行什么设置,以使会话至少存活8个小时?
Create a file and put <?php phpinfo() ?>
in it and check the output. 创建一个文件,并将
<?php phpinfo() ?>
放入其中,然后检查输出。
The value you want to look at is session.cookie_lifetime and session.gc_lifetime . 您要查看的值是session.cookie_lifetime和session.gc_lifetime 。
gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. gc_maxlifetime指定秒数,在此秒数之后,数据将被视为“垃圾”并可能被清除。 Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).
垃圾收集可能会在会话启动期间发生(取决于session.gc_probability和session.gc_divisor)。
In your script that is responsible for starting the sessions, you can put ini_set('session.gc_maxlifetime', 3600); // set session data life to 1 hour
在负责启动会话的脚本中,可以放置
ini_set('session.gc_maxlifetime', 3600); // set session data life to 1 hour
ini_set('session.gc_maxlifetime', 3600); // set session data life to 1 hour
or any other time that is suitable for your application. ini_set('session.gc_maxlifetime', 3600); // set session data life to 1 hour
或其他适合您的应用程序的时间。
In fact, you don't want to want the session don't die. 实际上,您不想让会话不死。
It's against session nature. 这是违反会议性质的。 A session is something what ends by definition.
会话是按照定义结束的。
Lasting admin session for the 8 hours makes no sense. 持续8个小时的管理会话毫无意义。
If you want to auto-renew it - use a cookie. 如果您想自动更新-使用cookie。 But don't touch session mechanism itself.
但是,请勿触摸会话机制本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.