PHP Session error hints and debugging _php tutorial

Source: Internet
Author: User
Tags php session

Q 1

Error message:

This kind of problem, because 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.

Q 2

Error message:

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

You can then create a temp directory under the C: \ directory.

Q 3

Error message:

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.

Q 4

How do I get the ID value of the current session?

The simplest method is: Echo SID; You're going to find out.

Q 5

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?

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.

Q 6

After using the session to log on to the main page, other pages how to use the session limit login.

The simplest way is to

Q 7

I registered the session variable with Session_register (), but when I use a header or a JavaScript redirect, I don't get access to the variable value registered by the session on the page. How can I resolve this?

The program fragment of the problem:

 
  

next.php

 
  

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:

In the jump to the next page, the session's current ID as a parameter, upload to the latter page.

Q 8

How does the session pass an array?

The method is to register and assign the value first.

Q 9

Can I access session values in a way like $http_get_vars[' * * '?

Yes, you can use the following global array to visit the session to enhance the security of your Web page. $HTTP _session_vars, $_session.

 
  

Please refer to this routine to modify the program that matches your own.

Q 10

What is the difference between session_unregister () and 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/752434.html www.bkjia.com true http://www.bkjia.com/PHPjc/752434.html techarticle Q 1 Error Hint: Warning:cannot send session cookie-headers already sent Warning:cannot send session cache Limiter-head ERs already sent this kind of problem because you are in the program ...

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