Session Time setup-php Tutorial

Source: Internet
Author: User
Session time setting this post was last edited by guliputaoyou in 2013-04-2311: 04: 18 because I cannot change the server configuration file, but I need to modify the user login time to 2 h. So I phpinfo and found gc_maxlifetime1440, so I checked a lot of information and used this function on the login page to replace the original session_st session time settings.

This post was last edited by guliputaoyou at 11:04:18

Because I cannot change the server configuration file, I need to change the user logon time to 2 h.
So I phpinfo and found that gc_maxlifetime = 1440,
So I checked a lot of information and used this function on the login page to replace the original session_start ().
Function start_session_custom ($ expire = 36000)
{
Ini_set ('session. gc_maxlifetime', $ expire );

If (empty ($ _ COOKIE ['phpsessid ']) {
Session_set_cookie_params ($ expire );
Session_start ();
} Else {
Session_start ();
Setcookie ('phpsessid ', session_id (), time () + $ expire );
}
}
Although setting $ expire to 36000 (10 h) still does not work.
In addition, there are a lot of session_start in a bunch of old code. do you want to replace all of them with start_session_custom?
I can only change it on the first session_start page (that is, the logon page?


Correct the following:
The full text shows that session_set_save_handler exists.
Where
While $ maxlifetime = 72000;
Function gc ($ maxlifetime)
{
If (rand (1000) %! = 0) return false;
$ Expiretime = $ this-> now-$ maxlifetime;
Return $ this-> db-> query ("delete from $ this-> table WHERE 'Last _ active' <$ expiretime ");

}


------ Solution --------------------
The principle is: set before session_start; otherwise, it is invalid.

You can put your code in a public file (all programs will load it), and delete session_start from other files.
If you find it troublesome, you can run your project in the php 5.4 environment.
Php 5.4 will issue a warning to the recurring session_start, so it is convenient to modify it accordingly.

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.