PHP Get visitors Real IP address in my time we need to get the user's real IP address, for example, log records, geo-location, user information, website data analysis, in fact, get the IP address is very simple $_server[' remote_addr '] on it.
PHP Tutorial Get visitor Real IP address
In my time we need to get the user's real IP address, for example, log records, geo-location, user information, website data analysis, in fact, get the IP address is very simple $_server[' remote_addr '] on it.
*/
The simplest way
$ip = $_server[' remote_addr ');
The above method as long as the use of proxy you can not get the real IP address, the following more detailed method
echo "Remote addr:". $_server[' REMOTE_ADDR ']. "
";
echo "x forward:". $_server[' Http_x_forwarded_for ']. "
";
echo "Clien IP:". $_server[' Http_client_ip ']. "
";
Well, look at an example.
function GetIP () {
$ip = $_server[' remote_addr ');
if (!empty ($_server[' http_client_ip ')) {
$ip = $_server[' http_client_ip ');
} elseif (!empty ($_server[' http_x_forwarded_for ')) {
$ip = $_server[' http_x_forwarded_for ');
}
return $IP;
}
/*
If it is an encrypted proxy, the real IP address cannot be obtained.
http://www.bkjia.com/PHPjc/631731.html www.bkjia.com true http://www.bkjia.com/PHPjc/631731.html techarticle PHP Get visitors real IP address in my time we need to get the user's real IP address, for example, log records, geo-location, user information, website data analysis, in fact, get ...