Do you obtain your user's router IP or computer IP from the PHP server variable $_SERVER['REMOTE_ADDR']?

Quoting ElrondCT from my previous question :

"Note also that your router and your computer are completely independent in getting addresses; you can have a static IP address for your router with a dynamic IP for your computer, or vice versa, or both can be of the same type (either one). Getting a static IP from an ISP is typically much more expensive (because it allows you to run as a web node, directly accessible by anyone); for your internal network, it's no big deal. If you go the dynamic route, your router provides the address to your computer, while your ISP provides the address to your computer. Therefore, a dynamic IP address for your computer is subject to change whenever either the computer or the router is restarted; a dynamic IP address that the router gets from the ISP is subject to change when the router is restarted or when the connection to the ISP is lost."

Which IP Address do you obtain from $_SERVER['REMOTE_ADDR']? Router or computer?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You will obtain the users front-facing IP.

Eg. If a user with an ISP issued static ip on his pc accessed this, you would see that static ip.
If a user sitting in a corporate network did the same, you would see the address of their router / proxy / firewall.

Essentially you will obtain the deepest public ip from that users pc that their firewalls / proxies allow.
$_SERVER values are populated from the http request, so REMOTE_ADDR will display whatever IP made the request.  So, in brief, you'll never know what client actually made the request.  You can't typically see behind a proxy, firewall or router.

If the client (browser) is behind NAT or a proxy, it will show the router/nat server/proxy IP.  If the client has a (real) static IP, it will show the client IP.  This is not  always the case, as there can be some dynamically assigned DHCP addresses which are not proxied, and static IP addresses which are pseudo IPs, but you wouldn't know that from the server side.

Here is a function I use and usually works well for getting their IP address even when they are behind a proxy by using "HTTP_X_FORWARDED_FOR" variable.  As others pointed out it may be hit and miss but this function is about the best I've ever used.

function getRealIpAddr()
      if (!empty($_SERVER['HTTP_CLIENT_IP']))
      elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
      //to check ip is pass from proxy
      // Don't show an IP if we can only find an RFC1918 private address
      if (substr($ip, 0, 3) == '10.' OR substr($ip, 0, 3) == '172' OR substr($ip, 0, 3) == '192')
            $ip = "PRIVATE";
      return $ip;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.