<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<title id="titlename" >IP,身份证,手机归属地查询接口</title>
</head>
<body>
<form  method="POST">
查询类型:
<select name="type" >
<option value="mobile">手机号</option>
<option value="ip">IP</option>
<option value="id">身份证</option>
</select>
输入信息:<input type="text" name="inputstr">
<input type="submit" name="submit" value="查询">
</form>
<?php
$type=empty($_POST['type'])?'':$_POST['type'];
$inputstr=empty($_POST['inputstr'])?'':$_POST['inputstr'];
$apiArr=array(
        'ip'=>'http://www.youdao.com/smartresult-xml/search.s?type=ip&q=',
        'mobile'=>'http://www.yodao.com/smartresult-xml/search.s?type=mobile&q=',
        'id'=>'http://www.youdao.com/smartresult-xml/search.s?type=id&q='

 

);
if(!empty($_POST['submit']))
{
     $url=$apiArr[$type];     
     if(empty($url))echo '<br/>暂不支持此类型查询';
     $contents=file_get_contents($url.$inputstr);
     $contents=iconv('gbk','UTF-8',$contents);
     echo '<hr>查询结果:',$contents;
}
?>
</body>
</html>

 

方法二.使用QQ的接口获得用户IP

 

function get_ip_place($city=0){   
     $ip=file_get_contents("http://fw.qq.com/ipaddress");  
     $ip=iconv('gbk','UTF-8',$ip);
     $ip=str_replace('"',' ',$ip);   
     $ip2=explode("(",$ip);   
     $a=substr($ip2[1],0,-2);   
     $b=explode(",",$a);   
     if($city)
     {
         $cityName=trim(str_replace('市','',$b[2]));
         if(!empty($cityName))
         {
             return $cityName;
         }else{
             return '';
         }
     }
     return $b;   
 }

 

 

方法三:

function get_ip_place(){   
     $url='http://www.youdao.com/smartresult-xml/search.s?type=ip&q='.getonlineip(); 
     $contents=file_get_contents($url.$inputstr);
     $xml =simplexml_load_string($contents);
     $addstr=$xml->product->location;
     $strpos=stripos($addstr,' ');
     if($strpos>0)
     {
         $addstr=substr($addstr,0,$strpos);
     }
     $addstr=str_replace(array('市','省'),array('|','|'),$addstr);
     $addArr=explode('|',$addstr);
     if(empty($addArr[2]))
     {
         return $addArr[0];
     }elseif(!empty($addArr[1])){
         return $addArr[1];
     }else{
         return '';
     }
 }

posted on 2010-11-01 11:27  mynetstudy  阅读(300)  评论(0)    收藏  举报