PHP Session never Expires Setup method _php Tutorial

Source: Internet
Author: User
Tags php session
This article introduced a few about the PHP session never expires in the Setup method, do not modify the program is the best way, because if the program is modified, the test department must be very depressed like me, then only modify the system environment configuration, is actually very simple, open php.ini settings 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 also set it to 99999999.

That's all OK, of course, if you don't believe it, just test it--set a session value after a 10-day half-month return to see if your computer is not powered down or down, you can still see this sessionid.

Of course, you may not have control of the server permissions and not as fortunate as I can modify the php.ini settings, all depend on ourselves there is a way, of course, you must use the client to store cookies, the resulting sessionid stored in the client's cookie, set the value of this cookie, and then the This value is passed to the session_id () function, as follows:

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
?>

If long after (how long?) See for yourself) you come back to refresh this page, the output number is 1 bigger than when you go that's right! If a lot bigger, it is estimated who moved your computer, this test is not accurate, hehe ... Go out for a while!

Note: The ' Phpsessid ' in the Setcookie line is not certain, and if you encounter a network administrator with a modified mania, he may have modified it, and the best way is to use the phpinfo () function to see Confirm the value of Session.name one item, compare science.

http://www.bkjia.com/PHPjc/632236.html www.bkjia.com true http://www.bkjia.com/PHPjc/632236.html techarticle This article introduces several ways to set up the PHP session never expires, do not modify the program is the best way, because if you modify the program, the test department must be very depressed like me, then ...

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