# PHP Predefined Variables

PHPServer Side ProgrammingProgramming

Any PHP script has access to a number of predefined variables. However, many of them are dependent on web server software, PHP version and other factors. Some of these variables are not available for a script running in command line mode. The $GLOBALS variable stores references of all globally available predefined varibles. Most of these variables are displayed by phpinfo.php Some of commonly used predefined variables are explained here. ##$_SERVER

This is an array variable that contains information about HTTP headers, script and environment. Following are some of prominent members of this array

PHP_SELF − stores filename of currently executing script. For example, a script in test folder of document root of a local server returns its path as follows −

## Example

<?php

echo "Age : " . $_GET["age"]; ?> ## Output This will produce following result − Name : xyz Age : 20 ##$_POST

An associative array of key-value pairs passed to a URL by HTTP POST method that uses URLEncoded or multipart/form-data content-type in request.

Data is sent to a PHP script using POST method by specifying action=POST in a HTML form test.html as below −

<form action="testscript.php" method="POST">
<input type="text" name="name">
<input type="text" name="age">
<input type ="submit" valaue="submit">
</form>

The PHP script is as follows −

## Example

<?php
echo "Name : " . $_POST["name"] . "<br>"; echo "Age : " .$_POST["age"];
?>

## Output

This will produce following result −

Name : xyz
Age : 20

?>

## Output

Array ( [file] => Array ( [name] => hello.html [type] => text/html [tmp_name] => C:\xampp\tmp\php9647.tmp [error] => 0 [size] => 56 ) )

## $_SESSION This variable is an associative array of variables representing HTTP session. ##$_ENV

An array of environment variables form this predefined variable. These variables are imported into PHP's global namespace.