Learning Dynamic Web page PHP Technology FAQ Summary Answers

Source: Internet
Author: User
Tags ini

1: Why I can't get a variable

I post data name to another page on one page, why can't I get any value when I output $name?

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

Method One: Find the Register_global in the php.ini and set it to on.
Method Two: This extract ($_post) is placed at the front of the receiving page, and extract ($_get) must have extract () before the $_session (Session_Start) is attached.
Method Three: One reads the variable $a=$_get["a"]; $b =$_post["B"] and so on, this method although troublesome, but relatively safe.

2: Debug Your Program

You must know the value of a variable at run time. I did that by creating a document debug.php, which reads as follows:

PHP Code:

? Php
Ob_start ();
Session_Start ();
Echo "<pre>";

Echo "The _get variables obtained on this page are:";
Print_r ($_get);

Echo "The _post variables obtained on this page are:";
Print_r ($_post);

Echo "The _cookie variables obtained on this page are:";
Print_r ($_cookie);

Echo "The _session variables obtained on this page are:";
Print_r ($_session);

Echo "</pre>";
?>

Then set up in php.ini: include_path = "c:/php" and place debug.php in this folder, and then you can include the file in each page to see the variable name and value.

3: How to use Session

When it comes to session, you must call the function session_start ();

Paying for the session is simple, such as:

PHP Code:

<?php
Session_Start ();
$Name = "This is a session example";
Session_register ("Name");/pay attention to, do not write: Session_register ("$Name");
Echo $_session["Name"];
Then $_session["Name" as "This is a session example"
?>

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

PHP Code:

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

Canceling a session can be like this:

PHP Code:

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

Cancel a session variable above php4.2 and bug.

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.