PHP—Retrieving 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,



getenv(REMOTE_ADDR)


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:

Next (Manipulating Variables)