Home > Backend Development > PHP Problem > Are there any other ways to collect form data besides $_GET and $_POST?

Are there any other ways to collect form data besides $_GET and $_POST?

醉折花枝作酒筹
Release: 2023-03-11 21:14:01
Original
1721 people have browsed it

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[&#39;PHP_SELF&#39;];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>

<?php 
$name = htmlspecialchars($_REQUEST[&#39;fname&#39;]); 
echo $name; 
?>

</body>
</html>
Copy after login

The result is

Are there any other ways to collect form data besides $_GET and $_POST?

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

tag. In this example, we specify a file to process form data. If you want another PHP file to handle this data, you can modify the specified script file name. We can then use the super global variable $_REQUEST to collect input field data in the form.

Let’s take a closer look at the difference between $_REQUEST, $_POST and $_GET.

$_REQUEST[] has the functions of $_POST[] and $_GET[], but $_REQUEST[] is slower. All data submitted through the post and get methods can be obtained through the $_REQUEST array.

EGPCS means to use the $_REQUEST array to obtain the priority of the content. The meanings of the letters are: E represents $_ENV, G represents $ _GET, P stands for $_POST, C stands for $_COOKIE, and S stands for $_SESSION. The data that appears later will overwrite the data written earlier. The default data writing method is EGPCS, so the data contained in POST will overwrite the data using the same keyword in GET.

That’s all. If you want to know anything else, you can click here. → →

php video tutorial

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template