In the previous article, we learned about "$_POST" and "$_GET". If you need it, please read "Do you know what PHP uses to collect form data? 》. This time we introduce to you another method "$_REQUEST" for collecting form data in PHP. You can refer to it if necessary.
In the previous article we introduced "$_POST" and "$_GET", but we forgot to introduce "$_REQUEST", this article will introduce the last part, let php collect the form The data party ended perfectly.
First of all, let’s take a look at chestnuts. This has become our convention.
<!DOCTYPE html> <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php $name = htmlspecialchars($_REQUEST['fname']); echo $name; ?> </body> </html>
The result is
In order to contrast with the "$_POST" in the previous article, I deliberately wrote the chestnut to be similar to "$_POST" . But just looking at the results, there seems to be no difference. We all enter information in the input box. When we click submit, the information we just entered will appear on the page. Let's take a look at the code again. It seems that there is a difference in the code. The method attribute value of the form tag is still post, but there is a gap between "<?php
" and "?>
" It is no longer "$_POST['fname']
", but "$_REQUEST['fname']
". This may be the local difference between them.
Of course, let’s take a closer look at $_REQUEST first.
PHP $_REQUEST is used to collect data submitted by HTML forms. When a user submits form data by clicking the "Submit" button, the form data is sent to the script file specified in the action attribute of the
The above is the detailed content of Are there any other ways to collect form data besides $_GET and $_POST?. For more information, please follow other related articles on the PHP Chinese website!