definitive way to get user ip address php [duplicate]
Possible Duplicate:
Function to get user ip address
<?PHP
$ipaddress = $_SERVER["REMOTE_ADDR"];
echo "Your IP is $ipaddress!";
?>
I was told this way of getting ip address has issues such as being able to fool. Is there a better way to gather ip address? looking for tutorials of better way to get ip address?
$_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.
精彩评论