1: Why can’t I get the variable
I POST data name from one web page to another web page, why can’t I get any value when I output $name?
In PHP4.2 and later versions, register_global defaults to off
If you want to get the variables submitted from another page:
Method 1: Find register_global in PHP.ini and set it For on.
Method 2: Put this extract($_POST);extract($_GET);(note that there must be Session_Start() before extract($_SESSION)) at the front of the receiving web page.
Method 3 :Read variables $a=$_GET["a"];$b=$_POST["b"] one by one. Although this method is troublesome, it is safer.
2: Debugging your program
You must know the value of a certain variable at runtime. This is what I did, create a file debug.php with the following content:
PHP code:
Ob_Start();
Session_Start();
Echo ""</font><font color="#007700">; <br><br> Echo </font><font color="#dd0000">"The _GET variables obtained on this page are: "</font><font color="#007700">;<br></font><font color="#0000bb">Print_R</font><font color="#007700">(</font><font color="#0000bb">$_GET</font><font color="#007700">);<br><br> Echo </font><font color="#dd0000">"The _POST variables obtained on this page are: "</font><font color="#007700">;<br></font><font color="#0000bb"> Print_R</font><font color="#007700">(</font><font color="#0000bb">$_POST</font><font color="#007700">);<br><br> Echo </font><font color="#dd0000">"The _COOKIE variable obtained on this page is :"</font><font color="#007700">;<br></font><font color="#0000bb"> Print_R</font><font color="#007700">(</font><font color="#0000bb">$_COOKIE</font><font color="#007700">);<br><br> Echo </font><font color="#dd0000">"The _SESSION variables obtained on this page are: "</font><font color="#007700">;<br></font><font color="#0000bb"> Print_R</font><font color="#007700">(</font><font color="#0000bb">$_SESSION</font><font color="#007700">);<br><br> Echo </font><font color="#dd0000">"
";
?>
Then set include_path = "c:/php" in php.ini, and put debug.php in this folder. You can include this file in each web page in the future and view the obtained variable names and values. .
3: How to use session
For anything related to session, the function session_start() must be called before;
Paying value for the session is very simple, 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"];
//Then $_SESSION["Name"] is "This is a Session example"
?>
After php4.2, you can pay directly for the session Value:
PHP code:
🎜> $_SESSION
[
"name"]="value"; ?> Cancel the session as follows:
This news has a total of
5
pages, currently at page
1
1
PHP code:
session_start();
session_unset();
session_destroy();
?>
There is a BUG in canceling a session variable in php4.2 and above.
Note:
1: There cannot be any output before calling Session_Start(). For example, the following is wrong.
============ ==============================
1 line
2 lines 3 lines Session_Start( );//There was already output in the first line before
4 lines....
5 lines?>
================= =========================
Tip 1:
Whenever ".... ....headers already sent..... ", which is the information output to the browser before Session_Start(). If you remove the output, it will be normal. (This error will also occur in COOKIE, and the cause of the error is the same )
Tip 2:
If your Session_Start() is placed in a loop statement and it is difficult to determine where the information was output to the browser before, you can use the following method:
Line 1
...Here is your program...
2: This What is the error
Warning: session_start(): open(/tmpsess_7d190aa36b4c5ec13a5c1649cc2da23f, O_RDWR) failed:....
Because you did not specify the storage path of the session file.
Solution:
(1) Create the folder tmp in the c drive
(2) Open php.ini, find session.save_path, and change it to session.save_path= "c:/tmp"
4: Why when I send variables to another web page, I only get the first half, and all the ones starting with spaces are lost
PHP code:
$Var="hello php";//Change to $Var= " Hello php"; Try to get what result
$post= "receive.php?Name=".$Var;
header("location:$post") ;
?>
Content of receive.php:
PHP code:
Echo ""</font><font color="#007700">;<br> Echo </font><font color="#0000bb">$_GET</font> <font color="#007700">[</font><font color="#dd0000">"Name"</font><font color="#007700">];<br> Echo </font><font color="#dd0000">"
";
?>
The correct method is:
PHP code:
🎜> $Var
="hello php";
$post= "receive.php?Name=".urlencode($Var);
header("location:$post");
?>
You don’t need to use Urldecode() on the receiving page, the variables will be automatically encoded.
This news has a total of