Home > Article > Backend Development > What should I do if the php session disappears after refreshing?
Solution to the problem that the php session disappears after refreshing: 1. Open the session through "session_start();"; 2. Write all public configurations in a php file; 3. The variable name cannot be the same as the array The labels are the same; 4. Check the storage path of the session data in phpinfo, and check whether the sessio in the file directory is saved successfully.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
Why is the php session gone after refreshing? manage?
ESSIONThe value becomes empty after refreshing the page, and the SESSION value cannot be obtained
1. The page using session must open session, that is, session_start();
2. If you want several pages to use a session together, then these pages must have an associated file to obtain the same session_id, so that the only session can be determined, so in the project, it is best Write all the public configuration in a PHP file, such as database configuration, session_satrt(), jump when not logged in, etc., and then reference it on other pages to get the same session.
3. Also note that the variable name cannot be the same as the array subscript, so that the session value will be cleared after refreshing the page, such as $user=$_SESSION['user']['name']. is wrong, the named variable cannot be the same as the session subscript.
4. If the problem still cannot be solved, you can check the storage path of the session data in phpinfo and check whether the sessio in the file directory is saved successfully.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if the php session disappears after refreshing?. For more information, please follow other related articles on the PHP Chinese website!