简体   繁体   中英

Get IP address of ISP with PHP

If I write in php $_SERVER['REMOTE_ADDR'] I get my ip : 176.xxx this address it's equal with the address who I get in cmd written ipconfig.

Now if I write in google find my ip I get another ip : 87.xxx

The question is: it's possible to get this ip 87.xxx with php?

Yes, it is possible by using $_SERVER['REMOTE_ADDR'] . Only thing to do is: place your script in internet on some free/nonfree webhosting.

You get your ip: 176.xxx because this ip is your ip in your local network and you run webserver on your computer (or other computer) which is in local network.

Your local network is connected to internet by router. Router connects 2 networks, so routerwise you have 2 ip addresses: local network ip (176.xxx) and internet ip (87.xxx) . Depending on the webserver location you will get one of these addresses.

When you google your ip, you are looking for it in internet. Webservers placed in internet will see your internet ip address. Btw. Your local network ip is masqueraded by NAT.

The geoip_isp_by_name() function will return the name of the Internet Service Provider (ISP) that an IP is assigned to

<?php
$isp = geoip_isp_by_name('www.example.com');
if ($isp) {
echo 'This host IP is from ISP: ' . $isp;
}
?>

User the following function to get the client IP. Hope it will work

function getClientIP() {
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM