PHP Set Session Life time detailed

Source: Internet
Author: User
Tags function prototype

The first method: Session_set_cookie_params

function prototype void session_set_cookie_params (int $lifetime [, String $path [, String $domain [, bool $secure = False [, bool $htt Ponly = false]]]

The code is as follows Copy Code

$lifetime = 3600; One hours

Session_set_cookie_params ($lifetime);

Session_Start ();

To set the lifetime of a session manually:

The code is as follows Copy Code


Session_Start ();
Save one day
$lifeTime = 24 * 3600;
Setcookie (Session_name (), session_id (), time () + $lifeTime, "/");
? >

The second method:

If you have the right to operate the server, setting this is very, very simple, just the following steps are required:

1, the "Session.use_cookies" set to 1, open the cookie store SessionID, but the default is 1, generally do not have to modify;
2, the "session.cookie_lifetime" Change to positive infinity (of course, there is no positive infinite parameters, but 999999999 and positive infinity is no difference);
3, the "Session.gc_maxlifetime" set to and "Session.cookie_lifetime" the same time;
4, modify 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.