Session time Set up

Source: Internet
Author: User
Session time setting
This post was last edited by guliputaoyou on 2013-04-23 11:04:18

Since I cannot change the server configuration file, I need to modify the time to keep the user logged in at 2h.
So I phpinfo a little bit and found gc_maxlifetime=1440,
So a lot of data, the function is used in 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 the $expire is set to 36000 (10h), it still does not work.
Another: a bunch of old code there is a lot of session_start, is it necessary to replace all the Start_session_custom?
I only change the first Session_Start page (that is, the login page).


To correct:
Read the full text and find Session_set_save_handler.
which
and $maxlifetime=72000;
Function GC ($MAXLIFETIME)
{
if (rand (0,1000)%1000!=0) return false;
$expiretime = $this->now-$maxlifetime;
return $this->db->query ("DELETE from $this->table WHERE ' last_activity ' < $expiretime");

}


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

You can put your piece of code in a public file (all the programs will load his type), and delete the session_start from the other files.
If you find it troublesome, then you can run your project in a PHP 5.4 environment.
PHP 5.4 warns of recurring session_start, which makes it easy to modify.
  • 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.