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 ));
?>