This site is mobile accessible. Press the "Tap Here" button to use a different font-size.
Tap Here!
Smartphone icons created by Freepik - Flaticon
CSS Fundamentals
HTML Fundamentals
JavaScript Fundamentals
SQL Fundamentals
PHP Fundamentals
Module 1. Intro
Module 2. Data Types
Module 3. Operators
Module 4. Arrays, Superglobals
Module 5. PHP Forms
Module 6. PHP Advanced
Module 7. PHP OOP
Module 8. MySQL Database
Module 9. PHP XML
Module 10. PHP - AJAX
4.2.5 $_GET
Super global variables are built-in variables that are always available in all scopes.
PHP $_GET
PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get".
$_GET can also collect data sent in the URL.
Assume we have an HTML page that contains a hyperlink with parameters:
<html>
<body>
<a href="test_get.php?subject=PHP&web=W3schools.com">Test $GET</a>
</body>
</html>
When a user clicks on the link "Test $GET", the parameters "subject" and "web" are sent to "test_get.php", and you can then access their values in "test_get.php" with $_GET.
The example below shows the code in "test_get.php":
<html>
<body>
<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>
</body>
</html>
$_GET in HTML Forms
A HTML form submits information via the HTTP GET method if the form's method attribute is set to "GET".
To demonstrate this, we start by creating a simple HTML form:
HTML Form
<html>
<body>
<form action="welcome_get.php" method="GET">
Name: <input type="text" name="name">
E-mail: <input type="text" name="email">
<input type="submit">
</form>
</body>
</html>
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, with your input, as query strings:
welcome_get.php?name=John&email=john@example.com
In the action file we can use the $_GET variable to collect the value of the input fields.
PHP code inside the welcome_get.php page:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
Tip: You will learn more about $_GET in the PHP Forms chapter.
Think SECURITY when processing PHP forms!
The example above does not contain any form validation, it just shows how you can send and retrieve form data.
Learn more about processing PHP forms with security in mind in the Form Validation chapter.
Proper validation of form data is important to protect your form from hackers and spammers!
Navigate this module
Eventually the navigation links, above, will be replaced by these << (previous) and >> (next) buttons below.
Animated PHP icons used in the buttons provided by ICONS8.COM .
Smartphone icons created by Freepik - Flaticon
Module 4 quiz
Example files created in this module:
PHP Arrays
Array Items
PHP Arrays - Get The Length of an Array with The count() Function
PHP Arrays - Change Value
Indexed Arrays - Loop Through an Indexed Array
PHP Arrays: Index Number part 1
PHP Arrays: Index Number part 2
PHP Arrays - Associative Arrays part 1
PHP Arrays - Associative Arrays part 2
PHP Arrays - Access Associative Arrays
PHP Associative Arrays: Change Key's Value
Associative Arrays - Loop Through an Associative Array part 1
Associative Arrays - Loop Through an Associative Array part 2
PHP Arrays - Two-dimensional Arrays
PHP Arrays - Two-dimensional Arrays with for loop
PHP Arrays - Sorting Arrays part 1
PHP Arrays - Sorting Arrays part 2
PHP Arrays - Sort Array in Descending Order rsort() part 1
PHP Arrays - Sort Array in Descending Order rsort() part 2
PHP Arrays - Sort Array (Ascending Order), According to Value asort()
PHP Arrays - Sort Array (Ascending Order), According to Key ksort()
PHP Arrays - Sort Array (Descending Order), According to Value arsort()
PHP Arrays - Sort Array (Descending Order), According to Key krsort()
PHP $GLOBALS
PHP $_SERVER
PHP $_REQUEST - Form Submission
PHP $_POST - Form Submission
Test Get
$_GET in HTML Forms
welcome_get page
PHP RegEx - Using preg_match()
PHP RegEx - Using preg_match_all()
PHP RegEx - Using preg_replace()
PHP RegEx - Grouping