Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
forms
url

PHP $_GET

Educative Answers Team

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 ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring