PHP $_GET
Variable
In PHP, the predefined $_GET variable is used to collect values from a form with method="get".
Information sent from a form with the GET method is visible to everyone (it appears in the browser's address bar) and has limits on the amount of information to send.
Example
The form.html file code is as follows:
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
</head>
<body>
<form action="welcome.php" method="get">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit" value="Submit">
</form>
</body>
</html>
When the user clicks the "Submit" button, the URL sent to the server looks like this:
http://www.tutorialpro.org/welcome.php?fname=tutorialpro&age=3
The "welcome.php" file can now collect form data via the $_GET variable (note that the form field names automatically become keys in the $_GET array):
Welcome <?php echo $_GET["fname"]; ?>!<br>
Your age is <?php echo $_GET["age"]; ?> years.
Demonstration of the above form execution:
When to Use method="get"?
When using method="get" in an HTML form, all variable names and values are displayed in the URL.
Note: This method should not be used when sending passwords or other sensitive information!
However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.
Note: The HTTP GET method is not suitable for large variable values. Its value cannot exceed 2000 characters.