<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> access to attribution through IP </title>
<body>
<form action= "" method= "POST" >
<p> Please enter IP address: <input type= "text" name= "IP"/></p>
<p><input type= "Submit" value= "Query"/></p>
</form>
<?php
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 external network 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));
?>
</body>