$_GET
contains an array of variables received via the HTTP GET method.
Variables can be sent using the HTTP GET method in two main ways:
A query string is additional data appended at the end of a URL. In the link below, everything following the ? sign constitutes the query string:
<a href="demo_phpfile.php?subject=PHP&web=W3schools.com">
|
The query string above includes two key/value pairs:
subject=PHP
web=W3schools.com
In the PHP file, we can use the $_GET
variable to retrieve the values from the query string.
The PHP file demo_phpfile.php
:
<html> <?php ?>
</body> |
An HTML form submits information via the HTTP GET method if the form’s method
attribute is set to “GET”.
To illustrate this, let’s create a simple HTML form:
HTML Form
<html> <form action="welcome_get.php" method="GET"> |
When a user clicks the submit button, the form data is sent to a PHP file specified in the action
attribute of the <form>
tag.
The form fields are sent to the PHP file as query strings with your input.
|
In the action file, we can use the $_GET
variable to retrieve the values of the input fields sent as query strings.
PHP code inside the welcome_get.php page:
<html>
</body> |
Remember to prioritize security when processing PHP forms! The example above demonstrates sending and retrieving form data without incorporating any form validation measures. |