PHP complete se...login
PHP complete self-study manual
author:php.cn  update time:2022-04-15 13:53:54

PHP $_GET variable



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


$_GET Variable

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

The information sent from a form with the GET method is visible to anyone (will be displayed in the browser's address bar), and there is a limit on the amount of information sent.

Example

form.html file code is as follows:

<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
<form action="welcome.php" method="get">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">
</form>
</body>
</html>
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" file can now be accessed via the $_GET variable Let’s collect form data (please note that the name of the form field will automatically become the key in the $_GET array):

欢迎 <?php echo $_GET["fname"]; ?>!<br>
你的年龄是 <?php echo $_GET["age"]; ?>  岁。
The above form execution demonstration:

5e817b9c1651373863b9cdb68fc2359.png

3145d119a87f66ef748d356d1640f9d.png


When to use method="get"?

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!

However, because the variable appears in the URL, it is possible to bookmark the page. In some cases, this is useful.

Note: HTTP GET method is not suitable for large variable values. Its value cannot exceed 2000 characters.

Recommended related practical tutorials: "PHP $_GET variable"

php.cn