The $_GET, $_POST, and $_REQUEST variables are PHP superglobals used to collect user input from forms and URLs. They allow data to be passed between web pages efficiently.
These superglobals are associative arrays automatically available in all PHP scripts. They do not require initialization.
// Accessing data sent through the URL query string
<?php
echo "Name: " . $_GET['name'];
echo "Age: " . $_GET['age'];
?>
Values are passed in the URL like ?name=John&age=25 and accessed using array keys.
// Collecting form data using POST method
<form method="POST">
Name: <input type="text" name="name">
Age: <input type="text" name="age">
<input type="submit">
</form>
<?php
echo $_POST['name'];
echo $_POST['age'];
?>
Form values are securely sent in the request body and accessed via $_POST.
// Accessing data from either GET or POST
<?php
echo $_REQUEST['name'];
?>
$_REQUEST works with both GET and POST data but should be used cautiously.
Below is a simple HTML form that demonstrates how POST data is collected.
$_POST for sensitive data.$_REQUEST in secure applications.