PHPRetrieving System Information
The web server provides environmental variables, which can be accessed by PHP
programs. PHP provides a function, getenv(), which, as its name suggests, gets
environmental variables. For example,
returns the IP address of whoever is viewing the PHP document.
You could use that value by assigning it to your own variable (e.g., IP_address)
and then doing something with that value (for example, echoing it):
$IP_address = getenv(REMOTE_ADDR);
echo "Your IP Address is $IP_address";
|
Here is a list of common system variables and what information
they provide:
- HTTP_ACCEPT - types of documents the web browser can interpret, e.g.,
images, Word documents, sound clips
- HTTP_USER_AGENT - type of web browser (both Microsoft Internet Explorer
and Netscape Navigator indicate "Mozilla," although Internet Explorer
also includes "MSIE")
- PATH_INFO - the directory where the web page is located, as seen by the
client
- PATH_TRANSLATED - the actual directory where the web page is located on
the server
- QUERY_STRING - text following a question mark (?) after the web address
(e.g., "http://www.website.org/search.php?dinosaur"); indicates
an argument to passed to the PHP program, such as a search term
- REMOTE_ADDR - The IP address of the client requesting the web page
- SCRIPT_NAME - the name of the "scripting software," in this case,
PHP
- SERVER_NAME - the name of the web server
- SERVER_PROTOCOL - the protocol used (usually HTTP:)
- SERVER_SOFTWARE - the software run by the web server
Next (Manipulating Variables)