Home  >  Article  >  Backend Development  >  What are the ways to pass values ​​in PHP forms?

What are the ways to pass values ​​in PHP forms?

藏色散人
藏色散人Original
2019-04-12 14:52:353451browse

This article mainly introduces two ways to pass values ​​in PHP forms, one is through the $_GET variable, and the other is through the $_POST variable. (Related recommendation: "PHP Tutorial")

Below we will introduce to you two ways to pass values ​​in PHP forms based on specific PHP code examples.

1. $_GET

In PHP, the predefined $_GET variable is used to collect values ​​from the form with method="get".

The form.html file code is as follows:




php中文网(php.cn)


名字: 年龄:

When the user clicks the "Submit" button, the URL sent to the server is as follows:

http://www.php.cn/welcome.php?fname=php&age=3

"welcome.php" The file can now collect form data through the $_GET variable (please note that the name of the form field will automatically become the key in the $_GET array):

欢迎 !
你的年龄是 岁。

As shown:

What are the ways to pass values ​​in PHP forms?

When using method="get" in an HTML form, all variable names and values ​​will be displayed in the URL.

Note: So this method should not be used when sending passwords or other sensitive information!

2. $_POST

In PHP, the predefined $_POST variable is used to collect values ​​from the form with method="post".

form.html file code is as follows:




php中文网(php.cn)


名字: 年龄:

When the user clicks the "Submit" button, the URL is similar to the following:

http://www.php.cn/welcome.php

"welcome.php" The file can now Form data is collected through the $_POST variable (please note that the name of the form field will automatically become the key in the $_POST array):

欢迎 !
你的年龄是 岁。

As shown:

What are the ways to pass values ​​in PHP forms?

The information sent from the form with the POST method is invisible to anyone, and there is no limit on the amount of information sent.

However, since the variable does not appear in the URL, the page cannot be bookmarked.

This article is an introduction to the two ways to pass values ​​in PHP forms, $_GET and $_POST. I hope it will be helpful to friends in need!

The above is the detailed content of What are the ways to pass values ​​in PHP forms?. For more information, please follow other related articles on the PHP Chinese website!

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