Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

PHP $_GET variable


May 11, 2021 PHP


Table of contents


PHP $_GET variable


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

The _GET is an array of variable names and values sent by the HTTP GET method.


$_GET variable

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

Information sent from forms with GET methods is visible to anyone (displayed in the browser's address bar) and there is a limit to the amount of information that can be sent.

Instance

 <form action="welcome.php" method="get">
 Name: <input type="text" name="fname">
 Age: <input type="text" name="age">
 <input type="submit">
 </form> 

When the user clicks the "Submit" button, the URL sent to the server looks like this:

//www.w3cschool.cn/welcome.php?fname=Peter&age=37

The welcome .php file can now collect form data from the $_GET variable (note that the name of the form field automatically becomes the key in the $_GET array):

Welcome <?php echo $_GET["fname"]; ?>.<br>
You are <?php echo $_GET["age"]; ?> years old!


When do I use method-"get"?

When you use method"get" in HTML forms, all variable names and values appear in the URL.

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

However, because variables appear in the URL, you can favorite the page in your favorites. In some cases, this is useful.

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

Read about it

HTTP Method: GET compares POST