Modify PHP Session Default Time Method _php Tutorial

Source: Internet
Author: User
Tags php session
PHP session is the default is 1440 seconds (24 minutes), if we want to let the session record does not expire what to do, next in our first to introduce the best way to not modify the program, because if you modify the program, the test department must be very depressed like me, then can only modify the system environment configuration, Actually very simple, open the php.ini setup file,

Modify line three as follows:

1, Session.use_cookies
Set this value to 1 and use a cookie to pass the SessionID

2, Session.cookie_lifetime
This represents sessionid the time that the client cookie is stored, the default is 0, which means that the browser shuts down SessionID. This is why the session of PHP cannot be used permanently! So let's set it to a number we think is big, 999999999 how, yes! That's it.

3, Session.gc_maxlifetime
This is the session data on the server side of the storage time, if more than this time, then the session data will be automatically deleted! Then we'll set it to 99999999.


If you cannot modify the php.ini file

The code is as follows Copy Code

Session_Start (); Start session
$_session[' count ']; Register Session variable Count
Isset ($PHPSESSID)? session_id ($PHPSESSID): $PHPSESSID = session_id ();
If $phpsessid is set, the SessionID is assigned to $PHPSESSID, otherwise it is generated SessionID

$_session[' count ']++; Variable count plus 1
Setcookie (' Phpsessid ', $PHPSESSID, Time () +3156000); Store SessionID into cookies
Echo $count; Displays the value of the session variable count
?>

http://www.bkjia.com/PHPjc/628957.html www.bkjia.com true http://www.bkjia.com/PHPjc/628957.html techarticle PHP session validity is 1440 seconds (24 minutes) By default, if we want to let the session record does not expire what to do, the next we introduce in the non-modification program is the best way, because such as ...

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