Methods to solve the problem that PHP cannot save the session: 1. Solve the problem of the folder where the session is saved; 2. You need to check whether there is any problem with the code. You need to close [session_auto] and write [session_start] at the top of the page. 】.
[Related learning recommendations: php programming (video)]
Solution to php failure Method of saving session:
1, php.ini setting problem, in this case you need to set
session_auto_start = on
//This is to automatically open the session
Enter phpinfo in the php document to check whether the session is opened correctly.
2. There is a problem with the folder where the session is saved.
First check whether session_save_path
in php.ini exists and has not been commented out. If it exists, it usually defaults to c:\windows\tmp in Widnows. This directory is not allowed to be read by other users by default.
Solution
1. Set the folder to be readable and writable by everyone. Although this can solve the problem, it creates a new problem, namely security issues, because it is under Windows. Cross-directory reading of registry and other information can be performed.
2. Reset session_save_path
. After the setting is completed, restart iis to see if it is successful. If not, please set two, because there are two in php.ini for compatibility with previous versions. One is commented out, one is above 4.0 and one is above 5.0. After the setting is completed, set the set directory to read and write by everyone, and then inherit it. Do not check other boxes. This ensures the security of the saved directory and the security of system data.
3. It has something to do with the program code.
When you see that sessions are generated in the set directory, but all are 0kb empty files, you need to check whether there is any problem with the code.
Solution:
1. If session_auto
is turned on, please turn it off. Then write session_start
at the top of the page 2. If the first solution is invalid, it is recommended to add the '@' symbol in front of session_start
and write Pages and read pages must be added.
4. Other issues
If the above reasons cannot be solved, please check whether the php document is the currently loaded php document, and the php.ini loaded by wamp In apache, please pay attention to the following article about checking the php.ini loaded in the current php environment.
[Related learning recommendations: php graphic tutorial]
The above is the detailed content of PHP cannot save session problem summary. For more information, please follow other related articles on the PHP Chinese website!