Per-application change
Insert the following PHP code at the top of your script's opening line (right after <?php):
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
}
Server wide change
1) Create and this content to file /usr/local/apache/htdocs/prepend.php with the following code:
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$_SERVER['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
}
?>
2) Set the variable auto_prepend_file in /usr/local/lib/php.ini to the following:
auto_prepend_file = "/usr/local/apache/htdocs/prepend.php"
3) Restart Apache (service httpd restart)