Trusted answers to developer questions

PHP $_GET

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

PHP $_GET is an associative array of variables passed to the current script via the URL parameters. $_GET is a PHP superglobal variablevariable that is accessible anywhere regardless of scope 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.

Example

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>
<?php
echo "Hello, " . $_GET['name']; // "Hello, John"
echo "Your age is " . $_GET['age']; // "Your age is 25"
?>
</body>
</html>

RELATED TAGS

php
forms
url
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?