简体   繁体   English

如果我不希望会话终止,应该更改哪个apache2 / php5配置?

[英]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? 我需要在htaccessphp 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_lifetimesession.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.

相关问题 我需要在文件 &#39;/etc/php5/apache2/php.ini&#39; 中的何处和什么进行更改以显示错误、警告、异常? 我应该如何保存我所做的更改? - Where & what I need to change in a file '/etc/php5/apache2/php.ini' to display errors, warnings, exceptions? How should I save the changes I made? 会话变量在PHP5 / Apache2 / Ubuntu12中不持久 - Session variables not persistent in PHP5/Apache2/Ubuntu12 我应该将我的PHP5对象存储在SPEED会话中,为什么? - Should I store my PHP5 Objects in session for SPEED, and why? php5编码:我没有检测到土耳其字符 - php5 encoding : I don't detect turkish characters 我想在端口82上的apache2上托管一个php网站。虚拟主机配置文件将如何? 我是新的 - i want to host a php site on apache2 on port 82. how will be the virtual host config file? I am new 在存在PHP5的情况下删除PHP 7后,Apache2不起作用 - Apache2 doesn't work after removing PHP 7 while PHP5 exists Php function serialize() 返回 s:value 但我不想要这个 's:'。我该怎么办? - Php function serialize() returns s:value but i don't want this 's:'.What should I do? Apache2,FastCGI,PHP5和不带.php sufix的网址 - Apache2, FastCGI, PHP5 and urls without .php sufix 安装PHP7后,Apache2仍在运行PHP5 - Apache2 still running PHP5 when PHP7 is installed PHP5文件在apache2中提供html输出 - PHP5 files giving output of html in apache2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM