Php obtains the Internet ip address of the computer through ip address

Source: Internet
Author: User
Php obtains the Internet ip address of the computer through the ip address. & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www. w3.orgTRxhtml1DTDxhtml1-transitional. dtd & quot; & gt; & lt php obtains the Internet ip address of the city through ip




Obtain the region through IP address



// Obtain the IP address
// $ Ip = $ _ SERVER ['remote _ ADDR ']; // automatically obtains the IP address of the client.
// Region corresponding to the ip address
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" ";
// Obtain the Internet ip address of the computer
Function getClientIp (){
$ Socket = socket_create (AF_INET, SOCK_STREAM, 6 );
$ Ret = socket_connect ($ socket, 'ns.dnspod.net ', 6666 );
$ Buf = socket_read ($ socket, 16 );
Socket_close ($ socket );
Return $ buf;
}
Echo getClientIp ();
$ Str1 = file_get_contents ("http://ip.taobao.com/service/getIpInfo.php? Ip = ". $ ip );
Var_dump (json_decode ($ str1, 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.