PHP Superglobals
Use this lesson when you want to understand the key concepts behind PHP Superglobals.
Several predefined variables in PHP are "superglobals", which means they are always accessible, regardless of scope - and you can access them from any function, class, or file without having to do anything special.
$GLOBALS: Used to access global variables from anywhere in the PHP script.$_SERVER: Holds information about headers, paths, and script locations.$_REQUEST: Used to collect data after submitting an HTML form.$_POST: Used to collect form data after submitting an HTML form with method="post". This is highly secure and does not show data in the URL.$_GET: Used to collect form data after submitting an HTML form with method="get". Data is visible in the URL.$_FILES: Contains items uploaded via the HTTP POST method.$_ENV: Contains environment variables.$_COOKIE: Used to retrieve cookie values.$_SESSION: Used to retrieve session values (temporary memory stored on the server).$_SERVERLet's look at $_SERVER to find the name of the file currently executing.
<?php echo $_SERVER['PHP_SELF']; echo "<br>"; echo $_SERVER['SERVER_NAME']; ?>
Superglobals are the essential bridge between the user's web browser and the server!