Home >Backend Development >PHP Tutorial >Collection of solutions to PHP session problems_PHP tutorial

Collection of solutions to PHP session problems_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:24836browse

The session function of PHP has always been difficult for many beginners. Even some veterans are confused sometimes. This article makes a simple summary of these issues for everyone’s reference.
 

1.
Error message
Warning: Cannot send session cookie - headers already sent
Warning: Cannot send session cache limiter - headers already sent
Analysis and solution
The reason for this type of problem is that when you use session_start() in the program, actual html content has been output before. Maybe you say, I don't have it, I just echo or print a message. Sorry, the output generated by your echo or print statement is the actual html content output. The way to solve this kind of problem is to move your session_start() to the first line of the program.


2.
Error message
Warning: open(F:/689phpsessiondatasess_66a39376b873f4daecf239891edc98b5, O_RDWR) failed
Analysis and solution
Such error statements are usually caused by you The session.save_path item in php.ini is not set properly. The solution is to set the session.save_path and session.cookie_path settings to
session_save_path = c: emp
session.cookie_path = c: emp
Then create a temp directory in the c: directory, you can

3.
Error message
Warning: Trying to destroy uninitialized session in
Analysis and solution
Out of class Such prompts are generally caused by you directly calling the session_destroy() function. Many friends think that the session_destroy() function can run independently, but this is not the case. The solution is to use session_start() to enable the session function before you call the session_destroy() function.


4. Question: How to get the id value of the current session?
The easiest way is:
echo SID;
You will find out.


5. Problem: My program does not have any output before calling the header function. Although I include a config.php file, there is no output in the config.php file. Why does the session still report the same error as in question 1? Is it because I used session_start() before the header?
Answer: Maybe you really checked your php program carefully and quoted the header () There is indeed no output before, and there is no output in your include file! But do you use the cursor keys to move the check after the end statement of the PHP code?>? Then you will find that after ?>, there is a blank line or a few spaces. If you delete these blank lines or spaces, the problem will be solved.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445211.htmlTechArticlePHP’s session function has always been difficult for many beginners. Even some veterans are confused sometimes. This article makes a simple summary of these issues for your reference...
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