Title: Questions about PHP - SESSION AUTHOR: Stangly Wrong
PHP's session function has been difficult for many beginners. Even some veteran, sometimes they are inexplicably. In this article, these questions will be a simple summary so that you can check it out.
1. Error Tip Warning: Cannot Send Sent Warning: Cannot Sendy Sent Warning: Cannot Sendy Cache Limiter - Headers Already Sent Analysis and Solution This kind of problem is that you have used session_start () in the program, it already The actual HTML content is output. Maybe you said, I didn't, I just a message of Echo or Print. Sorry, the output generated by your Echo or Print statement is the actual HTML content output. The way to solve this problem is to adjust your session_start () to the first line of the program.
2. Error Tip Warning: Open (f: / 689 / php / sessionData / sess_66a39376b873f4daecf239891edc98b5, o_rdwr) Failed analysis and solution The error statement is generally because of your php.ini about session.save_path is not set, The solution is to set the session.save_path and session.cookie_path set to session_save_path = c: / temp session.cookie_path = c: / temp then build a TEMP directory in the C: / directory,
3. Error Tip Warning: Trying to Destroy Uninitialized session in analysis and solution Out of this prompt, the general situation is caused by the session_destroy () function. Many friends think that the session_destroy () function can run independently, is there. The solution is to open the session_start () before you adjust 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 it.
5. Question: My program, there is no output before calling the Header function, although I include a config.php file, but there is no output in the config.php file, why SESSION is still reported to question 1 The same mistake, is it because I used Session_Start () before I was in Header? A: Maybe you really checked your PHP program, and there is no output before reference to Header (), and There is no output in your incrude file! But do you use the cursor keys?> This PHP code ends the statement after moving check? Then you will find it?> This back, there is a blank line or several spaces, you delete these spaces or spaces, then the problem is solved. Note: This issue, will be pHP4.1.2, higher, no test.
6. Q: After using the session to do the login master page, other pages are logged in with session restrictions. . . A: The easiest way is session_start (); if (! Session_register ('login "││ $ login! = True) {echo" You didn't land "; exit;}
7. Q: I registered with session_register (), but when I use Header or redirect statement with JavaScript, then in the page, I have access to the variable value registered by Session. How to solve it? Problem segment: session_start (); $ ok = 'love you'; session_register ('ok'); Header ("location: next.php");?> Next.php session_start (); Echo $ OK;?>
Solved method: When you use the Header function or Window.location, you will be easier to lose, and there is still no detailed answer to this problem. However, there is a solution. The header ("location: next.php". "?". SID); when jumping to the next page, the current ID of the session is used as a parameter, and it is passed to the latter page. Latest Solution: Open the php.ini file, find session.use_trans_sid = 0 to change it to session.use_trans_sid = 1 to resolve.
8.Session How to Bit Session_Register ('Data'); $ DATA = Array (1, 2, 3, 4);
The method is to assign a value after registration.
9. Question 9: Can I access the session value like a $ http_get_vars ['**']?
Answer: Yes, you can use the following Global array to access the session to enhance the security of the web page http_session_vars $ _SESSITION routine: session_start (); $ usrname = 'stangly.wrong'; session_register ('username');
Echo $ http_session_vars ['username']; echo ''; echo $ _SESSION ['UserName']; "Please refer to this routine to modify the program that meets your own procedure.
Question 10: What is the difference between session_unregister () and session_destroy ()? The main role of the session_unregister () function is to cancel the current session variable. However, pay attention is that if you use $ http_session_vars or $ _SESSION to reference the session variable in the current page, you may need to cooperate with the unset () to cancel the session variable. SESSION_DESTROY () is to clear the current Session environment. It means that when you use the session_destroy () function, then you can't use session_isregistered () to detect the variable of the session. But what you need to pay attention is that he cannot clear the session in Global or use the session in Session cookie. So before using session_destroy, it is best not to use $ http_session_vars $ _Session to access session. (Translated from php.net)
Routines: IF (isset ($ _ cookie [session_name ()])) {session_start (); session_destroy (); unset ($ _ cookie [session_name ()]);}
The above is the problem that some novices often encounter. Perhaps it is unclear, it is inevitable that it is wrong, please criticize the expert guidance.