PHP Setup Session survival time _php tutorial

Source: Internet
Author: User
To set PHP survival time we can use the Session_set_cookie_params function or modify the php.ini file Oh, the following small part to introduce.

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 the day
$lifeTime = 24 * 3600;
Setcookie (Session_name (), session_id (), time () + $lifeTime, "/");
? >

The second method:

If you have permission to operate the server, it is very, very simple to set up, just the following steps:

1, the "Session.use_cookies" set to 1, open the cookie storage SessionID, but the default is 1, generally do not change;
2, the "Session.cookie_lifetime" to the positive infinity (of course, no positive infinity parameters, but 999999999 and positive infinity is no difference);
3, the "Session.gc_maxlifetime" set to "Session.cookie_lifetime" the same time;
4. Modify the php.ini file session.gc.lifetime=10000

http://www.bkjia.com/PHPjc/632658.html www.bkjia.com true http://www.bkjia.com/PHPjc/632658.html techarticle to set PHP survival time we can use the Session_set_cookie_params function or modify the php.ini file Oh, the following small part to introduce. The first method: Session_set_cookie_params ...

  • 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.