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)

huangapple go评论60阅读模式
英文:

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();
英文:

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(); }

答案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();

huangapple
  • 本文由 发表于 2023年4月10日 18:36:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976338.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定