hutt132
Member
Apache Version: Apache/2.4.38 (Ubuntu)
PHP Version: 7.2.15
I'm hosting the website on an AWS server behind a load balancer. The website is logging every user's IP address as the private IP address of the load balancer instead of the user's public IP address.
In admin.php?tools/phpinfo on my site, the $_SERVER['REMOTE_ADDR'] variable is showing up as 172.30.0.200
The $_SERVER['HTTP_X_FORWARDED_FOR'] variable has my local machines public IP address.
To try to solve this, I edited the root index.php file to set $_SERVER['REMOTE_ADDR'] to $_SERVER['HTTP_X_FORWARDED_FOR']
However, now the website logs both the user's public IP AND the load balancer's private IP address at the same time ONLY when the user first logs into their account.
Once they are logged in, the website will continue to only log the load balancer's IP. The user's public IP won't be logged again until the user logs out and logs back in, where it will again log both IPs.
This is very odd behavior why it's logging both IPs only on logon even with the variable set in index.php.
PHP Version: 7.2.15
I'm hosting the website on an AWS server behind a load balancer. The website is logging every user's IP address as the private IP address of the load balancer instead of the user's public IP address.
In admin.php?tools/phpinfo on my site, the $_SERVER['REMOTE_ADDR'] variable is showing up as 172.30.0.200
The $_SERVER['HTTP_X_FORWARDED_FOR'] variable has my local machines public IP address.
To try to solve this, I edited the root index.php file to set $_SERVER['REMOTE_ADDR'] to $_SERVER['HTTP_X_FORWARDED_FOR']
Code:
if ($_SERVER['HTTP_X_FORWARDED_FOR']!==null && $_SERVER['HTTP_X_FORWARDED_FOR']!=='') {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
However, now the website logs both the user's public IP AND the load balancer's private IP address at the same time ONLY when the user first logs into their account.
Once they are logged in, the website will continue to only log the load balancer's IP. The user's public IP won't be logged again until the user logs out and logs back in, where it will again log both IPs.
This is very odd behavior why it's logging both IPs only on logon even with the variable set in index.php.