For PHP session function, always can not find the right answer, especially some errors, there are some error-free results, the most frightening is the latter, has been difficult for many beginners. On
Even some veteran, sometimes confused. In this article, we will make a simple summary of these questions so that we can consult them.
1.
Error hints
Warning:cannot send session Cookie–headers already sent
Warning:cannot Send session cache Limiter–headers already sent
Analysis and Solutions
The reason for this type of problem is that you use PHP in your program
Session_Start (), the actual HTML content has been output before. Maybe you said, I'm not, I'm just echo or print a message. I'm sorry, your
The output generated by the 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 hints
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, the solution is to
Session.save_path and Session.cookie_path settings are set to
Session_save_path = C:emp
Session.cookie_path = C:emp
Then create a temp directory under the C: directory to
3.
Error hints
Warning:trying to destroy uninitialized session in
Analysis and Solving methods
Out of class such a hint, the general situation is you directly adjust the Session_destroy () function caused. A lot of friends think that the Session_destroy () function can be independent
Run, not actually. The workaround is to use PHP before you tune the Session_destroy () function.
Session_Start () Opens the session function.
4. Question: How do I get the ID value of the current session?
The simplest way is to:
Echo SID;
You're going to find out.
5. Problem: My program does not have any output before calling the header function, although I include a config.php file, but in config.php
There is no output in the file, why does the session still report the same error as problem 1, because I used PHP before the header
Session_Start () for the sake of it?
A: Perhaps you really carefully check your PHP program, before the reference header () does not have any output, and in your include file does not have any output!
But do you use the cursor key to move the check after?> this PHP code closing sentence? Then you will find that after?> this, there is a blank line or a few spaces, and you have deleted these few empty lines or empty
, then the problem is solved.
Note: This issue will appear in PHP4.1.2, later versions, not tested.
6. Q: After using the session to log on the main page, the other pages how to use the session limit login ...
Answer: The simplest way is to
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 the header or a JavaScript redirect,
On the page, I don't have access to the variable value registered by the session. How can I resolve this?
The program fragment of the problem:
Session_Start ();
$
Ok
= 'love you';
Session_register ('ok');
Header ("location:next.php");
?>
next.php
Session_Start ();
Echo $ok;
?>
The workaround:
When you use the header function or the Window.location function, the session variable that you register on the previous page is easily lost, and the reason for this problem
No detailed answer has yet been answered.
But there is a way out. As shown below
Header ("Location:next.php". "?". SID);
In the jump to the next page, the session's current ID 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 first
9. Question 9: Can I use something like $http_get_vars['**'] Way to access the session value?
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:
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 matches your own.
What is the difference between the question 10:session_unregister () and the Session_destroy ()?
The main function of the Session_unregister () function is to eliminate the current Sion. (translated from Php.net)
Routines:
if (Isset ($_cookie[session_name ())) {
Session_Start ();
Session_destroy ();
Unset ($_cookie[session_name ());
}
Above, described is the PHP session_start () problem frequently encountered by some novice.