Logic
Bobby Billionaire
- Feb 8, 2012
- 748
- 207
Hello,
So as most of you know, when using a reverse HTTP proxy, you need your provider to set its headers to send the visitors real IP address instead of your proxy IP address to prevent everyone's IP being your proxy's IP address. That being said, the typical code placed in global.php to extract the visitors real IP address would be:
However, doing this doesn't allow anyone to login. So, I took it a bit further and created a file called ip.php with the following code:
Upon visiting that page, it outputs my proxy IP address which is where the problem is. My proxy provider mentioned to use HTTP_X_FORWARDED_TO, so I gave it a shot with the following code:
But by doing so, it lists the IP's as such:
With the first IP address listed, my IP address (real visitor IP address).
So he mentioned with that then to grab the first word in the string (assuming the real IP address), explode string with " " delimiter, and grab the first element. I'm not really familiar with PHP but I happened to find something that would hopefully work in this case:
But then again, it only extracts it down to just my proxy IP address. Ultimately, I've not found something that has successfully worked and would like some help. Sorry for the explaining but I want everyone to know the step-by-steps I took in attempts to resolve this. Yes, I'm currently using RevCMS as well.
Thank you!
So as most of you know, when using a reverse HTTP proxy, you need your provider to set its headers to send the visitors real IP address instead of your proxy IP address to prevent everyone's IP being your proxy's IP address. That being said, the typical code placed in global.php to extract the visitors real IP address would be:
Code:
if(isset($_SERVER['HTTP_X_REAL_IP'])){ $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];}
However, doing this doesn't allow anyone to login. So, I took it a bit further and created a file called ip.php with the following code:
Code:
<?php
echo $_SERVER['REMOTE_ADDR'];
Upon visiting that page, it outputs my proxy IP address which is where the problem is. My proxy provider mentioned to use HTTP_X_FORWARDED_TO, so I gave it a shot with the following code:
Code:
if(isset($_SERVER['HTTP_X_FORWARDED_TO'])){ $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_TO'];}
But by doing so, it lists the IP's as such:
Code:
69.136.xxx.xxx,104.197.xxx.xx,104.192.xxx.xxx
So he mentioned with that then to grab the first word in the string (assuming the real IP address), explode string with " " delimiter, and grab the first element. I'm not really familiar with PHP but I happened to find something that would hopefully work in this case:
Code:
if (!isset($_SERVER[”REMOTE_ADDR”]) && isset($_SERVER[”HTTP_X_FORWARDED_FOR”]))
{
$IP = array_pop(explode(”,”,$_SERVER[”HTTP_X_FORWARDED_FOR”]));
}
But then again, it only extracts it down to just my proxy IP address. Ultimately, I've not found something that has successfully worked and would like some help. Sorry for the explaining but I want everyone to know the step-by-steps I took in attempts to resolve this. Yes, I'm currently using RevCMS as well.
Thank you!