PHP Get visitor Real IP address _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.