In PHP, the predefined $_GET variable is used to collect values from the form with method="get".
The predefined $_GET variable is used to collect values from the form with method="get".
Information sent from a form with the GET method is visible to everyone (will be displayed in the browser's address bar), and there are limits on the amount of information sent.
The form.html file code is as follows:
<html><head><meta charset="utf-8"><title>Coder Tutorial (codercto.com)</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.codercto.com/welcome.php?fname=codercto&age=3
The "welcome.php" file can now collect form data via the $_GET variable (note that the names of the form fields automatically become keys in the $_GET array):
Welcome<?php echo $_GET["fname"]; ?>!<br>Your age is <?php echo $_GET["age"]; ?> years old.
When using method="get" in an HTML form, all variable names and values are displayed in the URL.
Note: So this method should not be used when sending passwords or other sensitive information!
However, because the variables appear in the URL, you can 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.