PHP $_GET
is an associative array of variables passed to the current script via the URL parameters. $_GET
is a PHP superglobal variable and can collect data sent in the URL.
$_GET
is also used to collect form data after submitting an HTML form with method="get"
.
You can also use $_POST to get form data. The difference between
$_GET
and$_POST
is that the former uses URL parameters to pass form data, while the latter uses the HTTP POST method.
Suppose a user visits the URL: http://example.com/?name=John&age=25
.
You can access the name
and age
parameters using $_GET['name']
and $_GET['age']
, respectively:
<html><body><?phpecho "Hello, " . $_GET['name']; // "Hello, John"echo "Your age is " . $_GET['age']; // "Your age is 25"?></body></html>
Free Resources