Contact Our Development Team
Free Code Tutorials & Open Source Code
Predefined Variables
Tutorials > PHP > Predefined Variables
PHP offers a number of predefined variables, which are set by the system and can provide useful information to your script. Here, we briefly explain some of the more useful ones. A full list is available in the PHP documentation.
$_SERVER
The $_SERVER variable is an array containing a number of elements that provide information about the server running the script, the client, and the connection. Some of these elements are explained below. Note that, depending on the environment in which the script is running (operating system, web server, etc.), not all elements may be available, so you should not rely on them unless you know your particular server environment will always provide them.
  • 'SERVER_ADDR' - The IP address of the server running the script, in dotted decimal format. (Example: "127.0.0.1")
  • 'SERVER_NAME' - The hostname of the server running the script. If the script is running under a virtual host, this will be the name of that virtual host. (Example: "www.openzu.com")
  • 'REMOTE_ADDR' - The IP address of the client from which the user is viewing the page, in dotted decimal format.
  • 'REMOTE_HOST' - The hostname of the client from which the user is viewing the page. This is based on a reverse DNS lookup, and the server must usually be configured explicitly to support it.
  • 'HTTP_REFERER' - The URL of the page (if any) which referred the user to the current page. This is set (or not set, as the case may be) by the user's web browser, and some browsers allow the user to modify this variable. It is often useful as a guide for traffic analysis, etc., but should not be considered trustworthy.
$_GET and $_POST
These variables contain information sent by the user's web browser using the HTTP GET and POST methods respectively. See the tutorial on handling user input for examples of how to use these in a script.
$_FILES
The $_FILES array contains details of any files uploaded by the user. Our handling uploaded files tutorial covers the use of this variable.
$_COOKIE
$_COOKIE is an array which contains any relevant cookies sent by the user's web browser. See the cookies tutorial for more details.
Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
     
Copyright ©2009, Wired IDS Ltd. | Licensed under Creative Commons Attribution Share-Alike | Load time: 0.3022 seconds