PHP Master lead the way--Question summary answer _php tutorial

Source: Internet
Author: User
1: Why don't I get the variable

I post data on one page to another page name, why is the output $name not get any value?

Register_global defaults to off in later versions of PHP4.2
To get a variable submitted from another page:

Method One: Find the Register_global in php.ini and set it to on.
Method Two: Put this extract ($_post) in front of the receiving page, extract ($_get);(Note Extract ($_session) must have Session_Start ()).
Method Three: A read variable $a=$_get["a"]; $b =$_post["B"), this method is troublesome, but relatively safe.

  2: Debug Your Program

At run time you must know why a variable is a value. I did this by creating a document debug.php, which reads as follows:

PHP Code:

   Ob_start ();
Session_Start ();
Echo "

";

Echo "This page has the _get variable:";
Print_r ($_get);

Echo "This page has the _post variable:";
Print_r ($_post);

Echo "This page has the _cookie variable:";
Print_r ($_cookie);

Echo "This page has the _session variable:";
Print_r ($_session);

Echo "
";
?>

Then set in php.ini: include_path = "c:/php", and put debug.php in this folder, in the future you can include this file in each page, view the resulting variable name and value.

   3: How to use Session

The function session_start () must be called before the session.

It is simple to pay for the session, such as:

PHP Code:

   Session_Start ();
$Name = "This is a session example";
Session_register ("Name");//note, do not write: Session_register ("$Name");
Echo $_session["Name"];
After the $_session["Name"] is "This is a SESSION example"
?>

After php4.2, you can pay a value for the session directly:

PHP Code:

   Session_Start ();
$_session["Name"]= "value";
?>

The cancellation session can be done like this:

This news a total of 5 pages, currently on the 1th Page 1 2 3 4 5


PHP Code:

   Session_Start ();
Session_unset ();
Session_destroy ();
?>

Cancel a Session variable above php4.2 there is a bug.

Attention:

1: cannot have any output before calling Session_Start (). For example, the following is an error.
==========================================
1 rows
2 rows 3 lines session_start ();//before the first line already has output
4 lines .....
5 Row?>
==========================================

Tip 1:

All the "... headers already sent ........" ", which is session_start () before outputting the information to the browser. Remove the output is normal, (the cookie will also appear this error, the same reason)

Tip 2:

If your session_start () is placed in a looping statement and it is difficult to determine where to export the information to the browser before, you can use the following method:
1 rows
........ Here is your program ...

2: What is wrong with this

Warning:session_start (): Open (/tmpsess_7d190aa36b4c5ec13a5c1649cc2da23f, O_RDWR) failed: ....
Because you did not specify a path to store the session file.

Workaround:
(1) Set up folder TMP on C disk
(2) Open php.ini, find Session.save_path, change to Session.save_path= "C:/tmp"


   4: Why do I transfer a variable to another page, only the first half of it, and all the ones that start with a space are lost

PHP Code:

   $Var = "Hello php";//modified to $var= "Hello php"; try to get what results
$post = "receive.php?" Name= ". $Var;
Header ("Location: $post");
?>

Content of receive.php:

PHP Code:

   Echo "

";
Echo $_get["Name"];
Echo "
";
?>

The correct method is:

PHP Code:

   $Var = "Hello php";
$post = "receive.php?" Name= ". UrlEncode ($Var);
Header ("Location: $post");
?>

In the Receive page you do not need to use UrlDecode (), the variable is automatically encoded.

This news a total of 5 pages, currently on the 2nd Page 1 2 3 4 5


5: How to intercept the specified length of Chinese characters without appearing to end with "?>", Beyond the section with "..." instead

In general, the variables to be intercepted from MySQL, first of all to ensure that the field length is long enough, usually char (200), you can maintain 100 characters, including punctuation.

PHP Code: <>< p="">

http://www.bkjia.com/PHPjc/532617.html www.bkjia.com true http://www.bkjia.com/PHPjc/532617.html techarticle 1: Why can't I get a variable i post data to another page in one page name, why does the output $name not get any value? In PHP4.2 later versions, Register_global defaults to OFF if you want to ...

  • <>

    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.