开发者

Change the expiry time of PHPSESSID Cookie

I have been at this for a day now, but nothing seems to be working. What I want to do: change the expiry time of the session cookie PHPSESSID, when a particular checkbox is checked , how do I do this ? I have开发者_运维知识库 tried:

ini_set()

session_set_cookie_params()

setcookie()

but nothing works . Can someone please please help me here ?

Thanks


To specify the session lifetime, server side, either apply the following command

  ini_set('session.gc_maxlifetime', 30*60); // expires in 30 minutes

or set it in your php.ini file.

To set the session cookie lifetime, client side, either let it as it is (0, will die when the browser is closed), or

  ini_set('session.cookie_lifetime', 30*60); // 30 minutes

or in the php.ini.

If you choose to use ini_set(), be sure to place the commands before session_start() is called.

Note that the ini_set function sets configuration option(s) during the script execution time only.

Regarding the checkbox and having a dynamic setting of the session lifetime, you could

  • use APC to store a setting shared by all PHP processes, that will last until the PHP server is down
  • write a value in a file somewhere that you load at the start of scripts (expensive) and set the value

(each script will have to ini_set() once before session_start())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜