The solution of the session never expires in PHP and its realization method

Source: Internet
Author: User
Tags ini modify php session php and client

Let PHP session never expire, you may not encounter such a depressing problem, but I met, very depressed.

We have developed a system that only the company's customer service personnel can use-a limited number of customer service personnel. This is the limited number of customer service staff a few days ago suddenly put forward such a problem: we every very short period of time (half an hour does not operate the page), is anxious to solve the customer problem, the system is prompted to login, delayed the customer's time ... This is very unpleasant!

The client is God, the only God. So Shangfeng requirements We can implement PHP session never expires, unless our customer service personnel to let him out of date. For security reasons I do not understand this never expired behavior, for the reason of laziness I really do not want to modify the previous program. But there is no way, I still need to change.

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 only modify the system environment configuration, in fact very simple, open the php.ini settings file, modify three lines as follows:

1, Session.use_cookies

Set this value to 1, using a cookie to pass the SessionID

2, Session.cookie_lifetime

This represents the SessionID in the client cookie store time, the default is 0, on behalf of the browser a close sessionid on the void ... That's why PHP's session cannot be used permanently! So let's set it to a number that we think is big, how about 999999999, it's OK!

3, Session.gc_maxlifetime

This is the session data stored on the server side of the time, if more than this time, then the session data will be automatically deleted! So we also set it to 99999999.

It's all OK, of course you don't believe it. 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 the SessionID.

Of course, you may not be able to control the permissions of the server and not as lucky as I can modify the php.ini settings, all rely on our own also have a way, of course, we must use the client to store cookies, the SessionID stored in the client's cookie, Set the value of this cookie, and then pass this value to the session_id () function, as follows:



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.