Home  >  Article  >  Backend Development  >  Summary and answers to frequently asked questions about learning dynamic webpage PHP technology_PHP tutorial

Summary and answers to frequently asked questions about learning dynamic webpage PHP technology_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:58:34806browse

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 variables submitted from another page:

Method 1: Find register_global in PHP.ini and set it to on.
Method 2: Put this extract($_POST);extract($_GET); at the front of the receiving web page (note that there must be Session_Start() before extract($_SESSION)).
Method 3: Read the variables $a=$_GET["a"];$b=$_POST["b"] one by one. Although this method is troublesome, it is safer.

2: Debug your program

The value of a variable must be known at runtime. This is what I did, create a file debug.php with the following content:

PHP code:

Ob_Start();
Session_Start();
Echo "

";<br>
<br>
Echo "The _GET variables obtained on this page are:";<br>
Print_R($_GET);<br>
<br>
Echo "The _POST variables obtained on this page are:";<br>
Print_R($_POST);<br>
<br>
Echo "The _COOKIE variables obtained on this page are:";<br>
Print_R($_COOKIE);<br>
<br>
Echo "The _SESSION variables obtained on this page are:";<br>
Print_R($_SESSION);<br>
<br>
Echo "
";
?>

Then set: include_path = "c:/php" in php.ini, and put debug.php in this folder. You can include this file in every 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 a 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:

PHP code:

Session_Start();
$_SESSION["name"]="value";
?>

You can cancel the session like this:

PHP code:

session_start();
session_unset();
session_destroy();
?>

There is a bug in canceling a certain session variable in php4.2 and above.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631988.htmlTechArticle1: Why can’t I get the variable? I POST data name from one web page to another web page, why is $name output? but can’t get any value? In PHP4.2 and later versions, reGISter_global defaults to off. If you want to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn