These are two different things related to the same thing: global variables.
$GLOBALS - PHP superglobal representing a global variable table, accessible as an array. Because it is superglobal, it is available everywhere.
An associative array containing references to all the variables that are currently defined in the global scope of the script. Variable names are array keys.
global - The keyword to import a specific global variable into the local variable table.
Then you asked:
But why can't we access session and cookie variables with $GLOBALS ?
Wrong, you can access session and cookie variables with $GLOBALS :
$GLOBALS['_SESSION']['session_variable_name']
However, $_SESSION also superglobal, so you do not need to use $GLOBALS and global to access session variables:
$_SESSION['session_variable_name']
The same goes for $_COOKIE .
hakre source share