Php session lifecycle settings

Source: Internet
Author: User
Tags php session
To set the php survival validity period, we can use the session_set_cookie_params function or modify the phpini file. The following is a brief introduction. Method 1: session_set_cook

To set the php survival validity period, we can use the session_set_cookie_params function or modify the php. ini file. The following is a brief introduction.

Method 1: session_set_cookie_params

Function prototype void session_set_cookie_params (int $ lifetime [, string $ path [, string $ domain [, bool $ secure = false [, bool $ httponly = false])

The code is as follows:

  1. $ Lifetime = 3600; // one hour
  2. Session_set_cookie_params ($ lifetime );
  3. Session_start ();

Run the following code to manually set the Session lifetime:

  1. Session_start ();
  2. // Save for one day
  3. $ LifeTime = 24*3600;
  4. Setcookie (session_name (), session_id (), time () + $ lifeTime, "/");
  5. ?>

Method 2:

If you have operation permissions on the server, it is very easy to set up, but you only need to perform the following steps:

1. set "session. use_cookies" to 1. enable the Cookie to store the SessionID. However, the default value is 1, which generally does not need to be modified;

2. change "session. cookie_lifetime" to positive infinity (of course there are no positive infinity parameters, but there is no difference between 999999999 and positive infinity );

3. set "session. gc_maxlifetime" to the same time as "session. cookie_lifetime;

4. modify the php. ini file session. gc. lifetime = 10000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.