PHP cannot send session cookie-headers already sent by solution _php Tutorial

Source: Internet
Author: User
It Cattle blog aggregation
Discover the best content of it technology, find the value of IT Technology home mobile News Cow List RSS Subscription about
Find what you are looking for, get what you want-upcoming it bull quiz

0
0---PHP cannot send session cookie–headers already sent by solution
Kitan published on April 23, 2012 17:20 | hits:108
Tag: Clutter | Cookie-headers | php | Session
Today, when transferring a blog to another VPS, this problem is encountered, prompting "Warning:session_start () [Function.session-start]: Cannot send session cookie–headers Already sent by ... ", not familiar with PHP, Google gets the solution:

Problem collection Solution for session

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 when you use Session_Start () in your program, you already have the actual HTML content output. Maybe you said, I'm not, I'm just echo or print a message. Unfortunately, the output generated by 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 hints
Warning:open (F:/689\PHP\SESSIONDATA\SESS_66A39376B873F4DAECF239891EDC98B5, O_RDWR) failed
Analysis and Solving methods
This error statement usually occurs because your php.ini is not set up for Session.save_path, and the workaround is to set the Session.save_path and Session.cookie_path settings to
Session_save_path = C:\Temp
Session.cookie_path = C:\Temp
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. 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 function before you Session_destroy () 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 there is no output in the config.php file, why does the session still report the same error as problem 1? Is it because I used the session_start () before the header?
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, you delete the empty lines or spaces, 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, I do not have access to the variable value registered by the session on the page. 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 registered on the previous page is easily lost, and there is still no detailed answer to the reason for this problem.
But there is a way out. As shown below www.2cto.com
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 access session values in a way 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:
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 session variable. 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 match the session variable with the unset ().
The Session_destroy () clears the current session environment. This means that when you use the Session_destroy () function, you can no longer use session_is_registered () to detect the variables in the session. However, it is important to note that he cannot clear the session in global or the session using 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 ();

Author Kitan

http://www.bkjia.com/PHPjc/478279.html www.bkjia.com true http://www.bkjia.com/PHPjc/478279.html techarticle It Cattle blog aggregation discovers the best content of it technology, find the value of IT technology home phone version News Cow List RSS Subscription about Find what you are looking for, get what you want-coming soon I ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.