IIS Web Server
PHP Tutorials
The $_SERVER variable and visitor IP address
The result of the following code:
<?php echo $_SERVER["REMOTE_ADDR"]; ?>
is:
38.107.179.236
Which is your IP address
Consider the following PHP code:
<table border="1">
<?php
foreach($_SERVER as $key => $value) {
echo "<tr><th>" . $key . "</th><td>" .$value . "</td></tr>\n";
}
?>
</table>
This code will output information in rows in a table. If you click the button below you will see it contains a lot of information about the visitor and the server.
To see the output of this code click here:
You will see that some values are not set for example no cookie was set so HTTP_COOKIE will have no value etc. Note that from PHP, HTTP_COOKIE would be accessed using the code:
<?php $_SERVER['HTTP_COOKIE'] ?>
other $_SERVER variables are accessed using:
<?php
$_SERVER['REMOTE_ADDR'];
$_SERVER['HTTP_REFERER'];
$_SERVER['QUERY_STRING'];
?>
.
