I have a website that is being accessed by internal people to the organisation. The organisation is using a proxy for using the Internet. The proxy server has a static IP (say 10.12.13.14) and port (3128). I want to check whether any request on my website home page is through the proxy server. I believe that the IPs during transfer via multiple gateway/hops or a proxy server are stored in the HTTP request headers (encapsulated).
My Environment details: PHP v5.6 Apache v2.4
Also, I have tried other methods answered here at stackoverflow as well but no help.
Method 1:
$proxy_headers = array(
'HTTP_VIA',
'HTTP_X_FORWARDED_FOR',
'HTTP_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED_FOR_IP',
'VIA',
'X_FORWARDED_FOR',
'FORWARDED_FOR',
'X_FORWARDED',
'FORWARDED',
'CLIENT_IP',
'FORWARDED_FOR_IP',
'HTTP_PROXY_CONNECTION'
);
foreach($proxy_headers as $x){
if (isset($_SERVER[$x])) die("You are using a proxy!");
}
Method 2:
$ports = array(8080,80,81,1080,6588,8000,3128,553,554,4480); // See Note
foreach($ports as $port) {
if (@fsockopen($_SERVER['REMOTE_ADDR'], $port, $errno, $errstr, 30)) {
die("You are using a proxy!");
}
}
Note: Don't know why he made an array of all ports so I removed all and kept 3128 only but it is then showing all request as non-proxied requests even when I am accessing it through the proxy.
I want to detect whether the person is from the proxy network or not and my logic is to check for proxy server IP i.e. 10.12.13.14 or Port i.e. 3128 in the headers through PHP. Currently, it is showing all request as non-proxied requests even when I am accessing it through the proxy.