Search code examples
httpproxyserveriphttp-proxy

Why HTTP_X_FORWARDED_FOR shows some ip address in my server


I have put same code to find proxy server in my two different server,but one of my server is showing this is proxy server.Finally i print all server variables and i could see that it has HTTP_X_FORWARDED_FOR in HTTP header. Why this happens?

code i used to find is

<?php

if ($_SERVER['HTTP_X_FORWARDED_FOR'] || $_SERVER['HTTP_X_FORWARDED'] || $_SERVER['HTTP_FORWARDED_FOR'] || $_SERVER['HTTP_CLIENT_IP'] || $_SERVER['HTTP_VIA'] || in_array($_SERVER['REMOTE_PORT'],array(8080,80,6588,8000,3128,553,554)) || @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 2))

{

    echo "Proxy detected";
    //Proxy detected'
}

else
{
    echo "Proxy not detected";
    //No Proxy detected
}

?>


Solution

  • X-Forwarded-For is typically inserted for a number of reasons.

    1. If your server is behind a reverse proxy, it's common for that reverse proxy to insert X-Forwarded-For in order to identify the original client IP to the back end server.

    2. If the client is behind a corporate proxy (common), that proxy may be inserting X-Forwarded-For due to any number of reasons. It's typically frowned upon, since it effectively leaks internal IP addresses, but it commonly happens if there are several chained proxies in use at the site.

    3. If the client is behind an open proxy hosted on the internet that proxy may be inserting the header.

    Proxies should also be adding the Via header, but they commonly don't.