Link to home
Start Free TrialLog in
Avatar of ChristmasRobyn
ChristmasRobyn

asked on

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 :https://www.experts-exchange.com/questions/25335030/What-happens-in-most-cases-regarding-dynamic-IP-addresses.html

"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?
Avatar of administratortools_net
administratortools_net
Flag of United Kingdom of Great Britain and Northern Ireland image

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.

ASKER CERTIFIED SOLUTION
Avatar of wfninpa
wfninpa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial