


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.

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
