PHP Session FAQ Collection and Solutions _php tutorial

Source: Internet
Author: User
Tags php session
PHP Session FAQ Collection and solutions:

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:/689PHPSESSIONDATASESS_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 () The reason for it?

A: Perhaps you really carefully check your PHP program, before the reference header () does not have any output, and in your include file also does not have any output! But do you use the cursor key to move the check after?> this PHP code closing sentence? So you'll find it in? > After this, there is a blank line or a few spaces, you delete the empty lines or spaces, then the problem is resolved.

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

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:

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 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 ();

Unset (_cookie[session_name ());

}

http://www.bkjia.com/PHPjc/815029.html www.bkjia.com true http://www.bkjia.com/PHPjc/815029.html techarticle PHP Session FAQ Collection and solutions: 1. Error message Warning:cannot send session cookie-headers already sent Warning:cannot send Sessio N Cache limiter-headers Alre ...

  • 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.