PHP Gets the address information of the city via IP to get the computer extranet IP

Source: Internet
Author: User
Tags get ip




Acquiring a place of attribution via IP



Get IP Address
$ip = $_server[' remote_addr '); Automatically get the IP of the client
IP-Corresponding region
if (!empty ($_post[' IP ')) {
$ip = $_post[' IP '];
interface address, which returns an XML result set, 1;
$str = file_get_contents ("http://ip.taobao.com/service/getIpInfo.php?ip=". $ip);
Var_dump (Json_decode ($str, true));
}


echo " ";
Get the computer's extranet IP
function Getclientip () {
$socket = Socket_create (Af_inet, Sock_stream, 6);
$ret = Socket_connect ($socket, ' ns1.dnspod.net ', 6666);
$buf = Socket_read ($socket, 16);
Socket_close ($socket);
return $buf;
}
Echo Getclientip ();
$str 1 = file_get_contents ("http://ip.taobao.com/service/getIpInfo.php?ip=". $ip);
Var_dump (Json_decode ($str 1,true));
?>

  • 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.