Why does PHP use $_session to make mistakes? Solution Ideas

Source: Internet
Author: User
Tags php session
Why does PHP use $_session to make mistakes?
session1.php:
session1.php
Session_Start ();
echo "Welcome: First Page
";
$_session[' MyWord ']= "I am Zhang San";
$_session["Myage"]= "18";
$_session["Mysex"]= "male";
echo "The MyWord value in the cookie is:". $_session[' MyWord '). "
";
echo "Next page";
?>

session2.php
session2.php
Session_Start ();
echo "Welcome: Page Two
";
echo "Name:". $_session[' MyWord '). "
";
echo "Age:". $_session["Myage"]. "
";
echo "Gender:". $_session["Mysex"]. "
";
echo "Next page";
?>
Open session1.php, Output
------------------------------------
Welcome: First Page
The MyWord value in the cookie is: I'm Zhang San.
Next page
------------------------------------

Click "Next" to open the session2.php output

------------------------------------
Welcome: Second Page

notice:undefined Index:myword in R:\Program files\appserv\www\session\session2.php on line 5
Name:

notice:undefined index:myage in R:\Program files\appserv\www\session\session2.php on line 6
Age:

notice:undefined Index:mysex in R:\Program files\appserv\www\session\session2.php on line 7
Gender:
Next page
------------------------------------
Is it a configuration problem? My php.ini session is configured as follows:

Session.save_handler = Files

Session.save_path = "R:/program files/appserv/php5/session_tmp"

; Session.save_path = "N; Mode;/path "

Session.save_path = "R:/program files/appserv/php5/session_tmp"

(with three Session.save_path)

Session.cookie_domain = Cookies

(the others are not listed.)

------Solution--------------------
Session.cookie_domain =
Modify to this or comment out, and then restart the server
I estimate that this is not the case of reading the COOKIE PHPSESSID caused, you can use Print_r ($_cookie) to see if there is no PHPSESSID
------Solution--------------------
See Building, Session.cookie_domain do not mess set, how to set their own search. You test the binding domain name locally to do what.
------Solution--------------------
Send a session Summary:

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. 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 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 message
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:emp
Session.cookie_path = C:emp
Then create a temp directory under the C: directory to

3.
Error message
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 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.
  • 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.