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.