What are superglobals in PHP?
Superglobals are built-in variables that PHP creates by itself. They are available in every place of your script (inside functions and classes also), and you do not need the global keyword to use them.
| Superglobal | Use |
|---|---|
$_GET | Data sent in the URL |
$_POST | Data sent by a form using the POST method |
$_REQUEST | Data of GET, POST and cookies together |
$_SESSION | Session data of the current user |
$_COOKIE | Cookies sent by the browser |
$_FILES | Details of uploaded files |
$_SERVER | Server and request information, like the method and IP address |
$_ENV | Environment variables |
$GLOBALS | Access to the global variables |
<?php
echo $_SERVER["REQUEST_METHOD"];
?>
Output:
When the page is opened normally in the browser
GET
Note:
All the data in $_GET, $_POST and $_COOKIE comes from the visitor, so never trust it. Validate it and escape it before use. See PHP Forms Handling.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |