PHP session_start (Resolving) questions _php Tips

Source: Internet
Author: User

This article, will make a simple summary of these questions, so that everyone can consult.
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 PHP 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:emp
Session.cookie_path = C:emp
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 PHP session_start () to open the session function 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 quote the same error as question 1? , is it because I used PHP session_start () before the header?

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? Then you will find that 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 access 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 conforms to your own.

What is the difference between the

question 10:session_unregister () and Session_destroy ()? The main function of the
Session_unregister () function is to note the current Sion. (translated from Php.net)
Routines:
    if (Isset ($_cookie[session_name ())) {  
    session_ Start ();  
    Session_destroy ();  
    unset ($_cookie[ Session_name ()]);  
   }
, described above are some of the PHP session_start () problems that beginners often encounter. Perhaps the details are not clear, it is inevitable that the wrong place, please expert guidance criticism.

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.