Home >Backend Development >PHP Tutorial >elcomsoft wireless security au PHP session never expires solution ideas and implementation methods sharing

elcomsoft wireless security au PHP session never expires solution ideas and implementation methods sharing

WBOY
WBOYOriginal
2016-07-29 08:44:501146browse

We developed a system in the early stage that only the company's customer service personnel can use - a limited number of customer service personnel. It was these limited customer service staff who suddenly raised this question a few days ago: every very short period of time (half an hour without operating the page), when we were anxious to solve the customer's problem, the system prompted that we needed to log in, which was delayed. Customer's time... This is very unpleasant!
 Customer is God, the only God. So the boss asked us to realize that the session in PHP never expires, unless our customer service staff artificially lets it expire. I don't understand this never-expiration behavior for security reasons; I really don't want to modify the previous program for laziness reasons. But there is no way, I still need to change.
 The best way is not to modify the program, because if you modify the program, the testing department will be very depressed like me, so you can only modify the system environment configuration. In fact, it is very simple. Open the php.ini setting file and modify the three lines as follows:
1. session.use_cookies
Set this value to 1 and use cookies to pass sessionid
2. session.cookie_lifetime
This represents the time the SessionID is stored in the client cookie. The default is 0, which means that the SessionID will be invalidated as soon as the browser closes it... ...It is because of this that the PHP session cannot be used permanently! Then let's set it to a number that we think is very large, how about 999999999, that's ok! That's it.
 3. session.gc_maxlifetime
 This is the time that the Session data is stored on the server side. If it exceeds this time, the Session data will be automatically deleted! Then we also set it to 99999999.
 That’s it, everything is ok. Of course, if you don’t believe it, just test it and see - set up a session and come back after 10 days and a half. If your computer does not have a power outage or crash, you can still see it. This sessionid.
  Of course, it is possible that you do not have the authority to control the server and are not as lucky as me to be able to modify the php.ini settings. There is also a way to rely on ourselves. Of course, we must use the client to store cookies, and store the obtained session ID in In the client's cookie, set the value of this cookie, and then pass this value to the session_id() function. The specific method is as follows:

Copy the code The code is as follows:


session_start(); // Start Session
$_SESSION['count']; // Register Session variable Count
isset($PHPSESSID)?session_id($PHPSESSID):$PHPSESSID = session_id();
// If $PHPSESSID is set, it will SessionID is assigned $PHPSESSID, otherwise SessionID is generated
$_SESSION['count']++; // Add 1 to variable count
setcookie('PHPSESSID', $PHPSESSID, time()+3156000); // Store SessionID in Cookie
echo $count; // Display the value of the Session variable count
?>


If you come back and refresh this page after a long time (how long? You can see for yourself), the output number is 1 larger than when you left. By the way! If it is much larger, it is estimated that someone touched your computer and this test is not accurate. Haha... go out again for a while!
Note: The 'PHPSESSID' in the setcookie line is not certain. If you I met a network administrator who suffered from modification mania. He may have modified it. The best way is to use the phpinfo() function to check and confirm the value of session.name, which is more scientific.

The above has introduced the solution ideas and implementation methods of elcomsoft wireless security au PHP's session never expires, including the content of elcomsoft wireless security au. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn