PHP development basic tutorial $_GET variable
1. $_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 everyone (will be displayed in the browser's address bar), and there is a limit on the amount of information sent.
Example: The code is as follows
<html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <!-- 新建一个带有两个输入框和一个提交按钮的表单 --> <!-- action为提交的的那个页面,method为提交方式,有$POST和$GET两种 --> <form action="" method="get"> 名字: <input type="text" name="name"> <br/> 年龄: <input type="text" name="age"> <br/> <input type="submit" value="提交"> </form> <hr/> 大家好,我是 <?php echo $_GET["name"]; ?>!<br> 今年 <?php echo $_GET["age"]; ?> 岁。 </body> </html>
Enter your name and age, click to submit to the current page
Note: When copying to local testing, the address bar The information we entered has been added, the details are as follows
Note:
"?" is preceded by the file address
www.phpcourse.com is the virtual domain name I set up myself. If you are interested in how to set up the virtual domain name, you can search online
?name=小方&age=27 is the information submitted by the get method, also called the query string. If you submit it a few times, you will be able to discover its patterns
2. 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: Therefore, 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: The HTTP GET method is not suitable for large variable values. Its value cannot exceed 2000 characters.