Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide
 

PHP Superglobals

PHP supports the concept of auto globals or superglobals. These are variables that are available in any scope and are described in detail at PHP.NET superglobals documentation. The PHP support in Project Zero enables a subset of these superglobals for use by PHP script developers.

The list of supported superglobals are :

$_SERVER

The $_SERVER superglobal gives access to the Project Zero Server attributes and a few HTTP request attributes. The complete list of keys that are currently supported include :

Variable Value
$_SERVER['argv'] This variable returns the query string associated with a request
$_SERVER['DOCUMENT_ROOT'] Path to the application's root
$_SERVER['HTTP_ACCEPT'] The value of the Accept header
$_SERVER['HTTP_ACCEPT_CHARSET'] The value of the Acccept-Charset header
$_SERVER['HTTP_ACCEPT_ENCODING'] The value of the Accept-Encoding header
$_SERVER['HTTP_ACCEPT_LANGUAGE'] The value of the Accept-Language header
$_SERVER[HTTP_CONNECTION'] The value of the Connection header
$_SERVER['HTTP_HOST'] The value of the Host header
$_SERVER['HTTP_REFERER'] The value of the Referer header
$_SERVER['HTTP_USER_AGENT'] The value of the User-Agent header
$_SERVER['HTTPS'] The value 'https' if the request was made using the https transport
$_SERVER['REMOTE_ADDR'] The IP address of the client making the request
$_SERVER['REMOTE_HOST'] The host name of the client making the request
$_SERVER['REMOTE_PORT] The port number of the client making the request
$_SERVER['SCRIPT_FILENAME'] The file name of the script being invoked
$_SERVER['SCRIPT_NAME'] The name of the script being invoked
$_SERVER['SERVER_PORT'] The port number that the server accepted the request on
$_SERVER['REQUEST_METHOD'] The HTTP method of the request
$_SERVER['REQUEST_URI'] The URI associated with the HTTP request
$_SERVER['REQUEST_TIME'] The time stamp when the request was dispatched to the script

$_GET

The $_GET variable is used to access URL query parameters associated with an HTTP request. URL query parameters are most commonly used for HTTP GET requests, but they are in fact supported for all HTTP request types. For the following request:

/search?title=Rose&author=Eco

$_GET['title] will have the value "Rose" $_GET['author'] will have the value "Eco"

$_POST

The $_POST variable is similar to the $_GET variable except that it processes the body of the HTTP POST request if the content type of the body is application/x-www-form-urlencoded.

$_COOKIE

The $_COOKIE variable allows the script developer to query the cookies that were sent by the client for the request. If the cookie key uses the '[]' notation to denote an array accessor, the cookie values can be accessed through PHP arrays.

$_REQUEST

The $_REQUEST variable provides the contents of the $_GET, $_POST, and $_COOKIE arrays. Note that if a parameter with the same name appears in two (or three) of the individual arrays, the value for that parameter in $_REQUEST is undefined.

$HTTP_RAW_POST_DATA

The $HTTP_RAW_POST_DATA variable contains the raw post data that has been transmitted as part of the HTTP POST request. This variable is not available for application/x-www-form-urlencoded and multipart/form-data content types.

$_FILES

The $_FILES variable contains information about any files that were uploaded during the current HTTP request. Given the following HTML form:

<form action="http://localhost:8080/testupload.php">
<input type="file" name="myfile"/>
</form>

The $_FILES variable can be accessed by the following script:

<?php
echo $_FILES['myfile']['name'] . "\n";      // name of the file on the client
echo $_FILES['myfile']['type'] . "\n";      // content type - text/plain
echo $_FILES['myfile']['size'] . "\n";      // file length
echo $_FILES['myfile']['tmp_name'] . "\n";  // path to the temporary file on the server
echo $_FILES['myfile']['error'] . "\n";     // error code
?>

Note that currently the content type of the file is not being saved during the upload, so the value for $_FILES['myfile']['type'] will always be text/plain.

r3 - 23 Oct 2007 - 18:45:58 - csurface
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site