英文:
PHP Because of my new hosting firm my sessions started to end in half an hour idle time. How to change it with code (without php.ini or htaccess)
问题
checked this link: https://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php
but couldn't solve the issue...
$twenty_days = 60 * 24 * 20; // 20 days in minutes
session_cache_expire($twenty_days);
session_start();
AND TRIED
ini_set('session.cookie_lifetime', xxx);
ini_set('session.gc_maxlifetime', xxx);
EDIT: Solved with this:
session_set_cookie_params('604800', '/', null, true, true);
// Start the session
session_start();
英文:
checked this link: https://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php
but couldn't solve the issue...
> > $twenty_days = 60 \* 24 \* 20; // 20 days in minutes
session_cache_expire($twenty_days);
session_start();
AND TRIED
ini_set('session.cookie_lifetime', xxx);
ini_set('session.gc_maxlifetime', xxx);
EDIT: Solved with this:
session_set_cookie_params('604800', '/', null, true, true);
// Start the session
session_start(); }
答案1
得分: 0
session_set_cookie_params
可以用于设置会话cookie的过期时间(以及其他设置),如果您的主机设置了您不喜欢的session.cookie_lifetime
值。
在session_start()
之前,使用您的所需设置来调用它。
session_set_cookie_params(0, '/', null, true, true); // 在浏览器关闭时过期会话
session_set_cookie_params(86400, '/', null, true, true); // 一天的生存期
session_start();
英文:
session_set_cookie_params
can be used to set session cookie expiration (and other settings) if your host is setting a session.cookie_lifetime
value you don't like.
Call it with your desired settings before session_start()
.
session_set_cookie_params(0, '/', null, true, true); // expire session when browser closes
session_set_cookie_params(86400, '/', null, true, true); // one day lifetime
session_start();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论