Globals and Superglobals In addition to the rules for naming variables, there are rules regarding the availability of variables. In general, the assigned value of a variable is present only within the function or script where it resides. For example, if you have scriptA.php which holds a variable called $name with a value of joe, and you want to create scriptB.php that also uses a $name variable, you can assign to it a value of jane without affecting scriptA.php. The value of the $name variable is local to each script, and the assigned values are independent of each other. However, you can also define the $name variable as global in a script or function. If this is the case in scriptA.php and scriptB.php, and these scripts are connected, there will only be one value for the now-shared $name variable. In addition to global variables of your own creation, PHP has several predefined variables called superglobals. These variables are always present, and their values available to all of your scripts. Each of the following superglobals is actually an array of other variables: . $_GET contains any variables provided to a script through the GET method. . $_POST contains any variables provided to a script through the POST method. . $_COOKIE contains any variables provided to a script through a cookie. . $_FILES contains any variables provided to a script through file uploads. . $_SERVER contains information such as headers, file paths, and script locations. . $_ENV contains any variables provided to a script as part of the server environment. . $_REQUEST contains any variables provided to a script via any user input mechanism. . $_SESSION contains any variables that are currently registered in a session.]]>
This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others.
I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials.