definitive way to get user ip address php [duplicate]

$_SERVER['REMOTE_ADDR'] is the only reliable IP address you’ll get – it’s extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you’ll get the proxy’s address, not the user’s.

Any of the other header-based ones are unreliable, as HTTP headers are trivial to forge. You can use the information from them, if you’d like, as long as you don’t TRUST it.

Leave a Comment