PHP Session FAQ Highlights and solutions:
1.
Error tips
Warning:cannot send session Cookie-headers already sent
Warning:cannot Send session cache Limiter-headers already sent
Analysis and Solving methods
The reason for this kind of problem is that when you use Session_Start () in your program, you already have the actual HTML content output. Perhaps you say, I did not ah, I just echo or print a message. I'm sorry, the output from your Echo or print statement is the actual output of the HTML content. The solution to this type of problem is to transfer your session_start () to the first line of the program.
2.
Error tips
Warning:open (F:/689PHPSESSIONDATASESS_66A39376B873F4DAECF239891EDC98B5, O_RDWR) failed
Analysis and Solving methods
This error statement usually occurs because your php.ini about Session.save_path is not set up, and the solution is to set the Session.save_path and Session.cookie_path settings to
Session_save_path = C:temp
Session.cookie_path = C:temp
Then in the C: directory to create a temp directory, you can
3.
Error tips
Warning:trying to destroy uninitialized sessions in
Analysis and Solving methods
A class such as a hint, the general situation is that you directly adjust the Session_destroy () function caused. Many friends think that the Session_destroy () function can run independently, but it is not. The solution is to use Session_Start () to open the session before you tune the Session_destroy () function.
4. Question: How do I get the ID value of the current session?
The easiest way to do this is to:
Echo SID;
You're going to find out.
5. Question: My program does not have any output before calling the header function, Although I include a config.php file, but there is no output in the config.php file, why does the session still report the same error as question 1, because I used the session_start () before the header 's sake?
A: Maybe you did check your PHP program carefully and did not have any output before referencing header (), and there is no output in your include file! But do you use the cursor keys in the?> of this PHP code after the sentence to move the check? So you're going to find out? > After this, there is a blank line or a few spaces, you delete these empty lines or spaces, then the problem is solved.
Note: This problem will be in PHP4.1.2, later version, not tested.
6. Q: Use session to do login home page, other pages how to use the session limit login ...
Answer: The easiest way to do this is
Session_Start ();
if (!session_registered (' login ') ││login!= true) {
echo "You did not log in";
Exit
}
7. Q: I registered the session variable with Session_register (), but when I use header or JavaScript redirection statements, on the page, I can't access the value of the variable that the session registers. How can i solve this problem?
The program fragment of the problem:
Session_Start ();
OK = ' love for you ';
Session_register (' OK ');
Header ("location:next.php");
?>
next.php
Session_Start ();
echo OK;
?>
Way to solve:
When you use the header function or the function such as window.location, the session variable that you register on the previous page will be easily lost, and there is still no detailed answer to the reason of the problem.
But there are ways to solve them. As shown below
Header ("Location:next.php". "?". SID);
When you jump to the next page, the current ID of the session as a parameter, upload to the latter page.
8.session How to pass an array
Session_register (' data ');
Data=array (1,2,3,4);
The method is to register and assign the value before
9. Question 9: Can I access the session value in a way that is like http_get_vars[' * * '?
Answer: Yes, you can use the following global array to visit the session to enhance the security of the Web page
Http_session_vars
_session
Routines:
CODE:
Session_Start ();
Username = ' Stangly.wrong ';
Session_register (' username ');
echo http_session_vars[' username '];
Echo '
';
echo _session[' username '];
?>
Please refer to this routine to modify the program that conforms to your own.
What is the difference between the question 10:session_unregister () and Session_destroy ()?
The primary function of the Session_unregister () function is to note that the current session variable is deleted. Note, however, that if you use Http_session_vars or _session to refer to the session variable in the current page, you may need to work with unset () to eliminate the session variable.
and Session_destroy () is to clear the current session environment. This means that when you use the Session_destroy () function, you cannot use session_is_registered () to detect the session variables. However, it should be noted that he cannot clear the session in global or use the session in the session cookie. So before using Session_destroy, it's best not to use Http_session_vars _ Session to access the session. (translated from Php.net)
Routines:
if (Isset (_cookie[session_name ())) {
Session_Start ();
Session_destroy ();
Unset (_cookie[session_name ());
}