Session in php often has some strange problems. Many of these problems are minor details. it may be difficult for php beginners to find out the cause, today, we have collected almost all session problems
Session in php often has some strange problems. Many of these problems are minor details. it may be difficult for php beginners to find out the cause, today, we have collected all the problems or problems caused by Sessions and provided solutions one by one.
1> error message
Warning: Cannot send session cookie-headers already sent
Warning: Cannot send session cache limiter-headers already sent
The cause is that when session_start () is used in the program, actual html content is output. Even if a message is sent by echo or print, the output produced by the echo or print statement is the actual html content output. To solve this problem, set session_start () to the first line of the program.
2> error message
Warning: open (F:/webphpsessiondatasess_76666aecf239891edc98b5, O_RDWR) failed
This error occurs generally because the session. save_path item in your php. ini is not set. the solution is
Set session. save_path and session. cookie_path
Session_save_path = c: temp
Create a temp directory under the c: Directory.
3> error message
Error message: Warning: Trying to destroy uninitialized session in
This is generally because you directly call the session_destroy () function. many friends think that the session_destroy () function can be run independently, the solution is to enable the session function with session_start () before you call the session_destroy () function.
4> How to obtain the id of the current session?
The simplest method is echo SID;
5>There is no output before calling the header function, although I include a config. php file, but in config. there is no output in the PHP file. Why does the session still report the same error as Question 1? is it because I used session_start () before the header?
After carefully checking your php program, there is indeed no output before header () is referenced, and there is no output in your include file!
But are you using the mouse key?> What about the mobile check after the conclusion of this PHP code? Then you will find in?> There is a blank line or space behind this. if you delete these blank lines or spaces, the problem is solved.
Note: This problem occurs in PHP4.1.2.
6> after using session to log on to the home page, how can I use session to limit logon to other pages?
Solution:
- Session_start ();
- If (! Session_registered ('login') │ login! = True ){
- Echo "you have not logged on ";
- Exit;
- }
7>The session variable is registered with session_register (). However, when the header or javascript redirection statement is used, the variable value registered by the session cannot be accessed on the following page.
Program segment of the problem:
-