Latest web development tutorials

PHP $ _GET variable

In PHP, the predefined $ _GET variable is used in the form of value from the method = "get" collection.


$ _GET Variable

Forms predefined $ _GET variable is used to collect from the method = "get" the value.

Information form sent with the GET method from anyone is visible (will be displayed in the browser's address bar), and on the amount of transmission information is limited.

Examples

form.html file code is as follows:

<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</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 as follows:

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

"Welcome.php" file can now collect $ _GET variable to the form data (Note that the name of the form fields will automatically be the keys in the $ _GET array):

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

Demo execute the above form:


When to use method = "get"?

When using method = "get" in HTML forms, all variable names and values ​​are displayed in the URL.

Note: So when sending passwords or other sensitive information, should not use this method!

However, because the variables are displayed in the URL, you can collect the page in Favorites. In some cases, this is very useful.

Note: HTTP GET method is not suitable for large values of the variables.Its value is not more than 2000 characters.