As with the title of the article, there will be more and more discussions about PHP4.2 later editions and Register_globals.
If your PHP program is working correctly, but if you have an error upgrading to PHP4.2, please read the following carefully:
Previously, in your PHP, there might be a table like the following:
<form action= "page.php" method= "POST" >
<input type= "text" name= "variable"/>
<input type= "Submit" >
</form>
Also, you can access your variables as simple as the following:
<?php
Echo $variable;
?>
When upgrading to the PHP4.2 version of the problem--at the time of installation, PHP defaults to set the Register_globals=off, this register_globals is the php.ini set whether to allow direct use of variables in the above example $ Variable parameters, until the previous version of PHP4.2, Register_globals is default to ON, it is said that you can directly output variables. However, in later versions of PHP4.2, to prevent potentially unsafe code from spilling, the PHP development Group has register_globals defaults to OFF.
This means that the above code no longer has output.
[Translator Note: Through the processing of a series of PHP functions, you can also access variables directly in Register_globals=off. ]
In fact, when using the table above, we can access the values entered in several ways.
Because we use post to submit the data, we can use the _post array, for example:
<?php
echo $_post[' variable '];
?>
Alternatively, if the table above is submitted in Get mode, we can use the _get array:
<?php
echo $_get[' variable '];
?>
If you are not aware that you are using post or get to submit data for some reason, you can use all _request arrays, for example:
<?php
echo $_request[' variable '];
?>
The corresponding array variable names for cookies and sessions (sessions) are _cookie and _session, and you can access the values of the variables in the same way. There are _server, _files, _env and Globals arrays, all of which are PHP's global variables that can be used anywhere in PHP, including in functions and classes.
The following code can work correctly as well:
<?php
function Printpost ()
{
foreach ($_post as $key => $value)
echo "$_post[$key] => $value <br>";
}
?>
You do not need to use the statement ' Global $_post ' in the function, you can use the global variable directly.
For more information, please refer to the PHP online manual:
http://www.php.net/manual/en/language.variables.predefined.php
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.