a caution about HTTP_X_FORWARDED_FOR
any of the variables in the $_SERVER array that begin with HTTP_* are derived from the request headers the client browser sends. this means they can fake them quite easily.
if you want to see this in action, make 2 scripts.
server_vars.php.php
PHP Code:
<?php
print_r($_SERVER);
?>
request.php
PHP Code:
<?php
echo "<pre>\n";
$host = 'localhost';
//$host = 'www.example.org';
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
$out = "GET /server_vars.php HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
// add some headers that php will put into the _SERVER array for us
$out .= "X-FORWARDED-FOR: fake x_forwarded_for\r\n";
$out .= "FORWARDED-FOR: fake forwarded for\r\n";
$out .= "foo: im am foo\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
and run request.php and it will show you the output of server_vars.php
Bookmarks