So that the PHP session will never expire, you may not have encountered such a depressing problem, but I have encountered, very depressed.
We have developed a system that can only be used by our Customer Service staff-limited customer service staff. Just a few of our limited customer service staff suddenly raised the following question a few days ago: When we are worried about solving the customer's problem every very short time (not operating the page for half an hour, the system prompts you to log on, delaying the customer's time ...... This is unpleasant!
The customer is God, the only God. As a result, the peak demand is that we can achieve the PHP session never expire, unless our Customer Service Staff manually let him expire. For security reasons, I do not understand this kind of behavior that never expires. For laziness, I really don't want to modify the previous program. But there is no way. I still need to change it.
It is the best way not to modify the program, because if you modify the program, the test department will be very depressed, like me, so you can only modify the system environment configuration, in fact, it is very simple, open php. ini settings file. Modify the following three lines:
1. session. use_cookies
Set this value to 1 and use cookie to pass sessionid
2. session. cookie_lifetime
This indicates the time when SessionID is stored in the client Cookie. The default value is 0, indicating that the session ID will be voided once the browser closes it ...... This is why PHP sessions cannot be used permanently! So let's set it to a number that we think is big. How about 999999999? Yes! That's it.
3. session. gc_maxlifetime
This is the time when Session data is stored on the server. If this time is exceeded, Session data will be automatically deleted! Then we set it to 99999999.
So everything is okay. If you don't believe it, test it. Set a session value for 10 days and half a month, if your computer is not powered off or down, you can still see this sessionid.
Of course, you may not be able to modify php just as lucky as you do not have permission to control the server. ini settings, everything depends on ourselves. Of course, we must use the client to store cookies. The sessionID is stored in the client's cookie and the cookie value is set, then pass the value to the session_id () function. The procedure is as follows:
- <? Php
- Session_start (); // start the Session
- $ _ SESSION [count]; // registers the Session variable Count
- Isset ($ PHPSESSID )? Session_id ($ PHPSESSID): $ PHPSESSID = session_id ();
- // If $ PHPSESSID is set, the SessionID is assigned to $ PHPSESSID. Otherwise, the SessionID is generated.
- $ _ SESSION [count] ++; // variable count plus 1
- Setcookie (PHPSESSID, $ PHPSESSID, time () + 3156000); // store the SessionID to the Cookie
- Echo $ count; // display the value of the Session variable count
- ?>
If it takes a long time (how long? You can see it for yourself.) When you come back to refresh this page, the output number is 1 larger than when you go. That's right! If it's a lot bigger, it's estimated that someone has moved your computer. This test is inaccurate ...... Go out for a while!
Note: The 'phpsessid' in the setcookie line is not certain. If you have a network administrator with a modified mad disease, he may have modified it, the best way is to use the phpinfo () function to check the session. the value of name is relatively scientific.