文章利用了第三方接口来实现ip地址查询,这里根据用户提交的ip地址就可以方便的查出ip地址真实所在地。
代码如下 复制代码
0){$urlip=array_keys($_get);$urlip=str_replace(_,.,$urlip[0]);}?>
ip查询
ip地址或域名:
country;
if($ipdata->region==$ipdata->city){$ipaddress.=$ipdata->city;}else{$ipaddress.=$ipdata->region.$ipdata->city;}
$ipaddress.=$ipdata->isp;
echo 您查询的ip: [.$ip.]ip详细地址: [.$ipaddress.]
;
}else{echo ?澹?闶淙氲?p,居然不能查询到!不是输入错误?;}
$ipdaili=$_server['remote_addr'];
if(!in_array($ipdaili,array('127.0.0.1',$ip,$_server['server_addr'],get_real_ip()))){
echo 您的代理ip是[.$ipdaili.] 来自.ipdata($ipdaili).;
}
$whiosip=$_post['ip']?$_post['ip']:$urlip;
if($whiosip){preg_match('/((w|-)+.)+[a-z]{2,4}/i',$whiosip) ? $whois=str_replace(www.,,$whiosip):;}
if($whois){echo
点击查看域名 .$whois. 的whois信息;}
?>
ip国家/地区省份城市县运营商
=$ip;?> =$ipdata->country.$ipdata->area?> =$ipdata->region?> =$ipdata->city?> =$ipdata->county?> =$ipdata->isp?>
fetch($durl);
if($f->errno() == 0) $r=$content;
else $r=$f->errmsg();
return $r;
}
function get_real_ip(){
if(getenv('http_client_ip') && strcasecmp(getenv('http_client_ip'), 'unknown'))
{$ip = getenv('http_client_ip');}
elseif(getenv('http_x_forwarded_for') && strcasecmp(getenv('http_x_forwarded_for'), 'unknown'))
{$ip = getenv('http_x_forwarded_for');}
elseif(getenv('remote_addr') && strcasecmp(getenv('remote_addr'), 'unknown'))
{$ip = getenv('remote_addr');}
elseif(isset($_server['remote_addr']) && $_server['remote_addr'] && strcasecmp($_server['remote_addr'], 'unknown'))
{$ip = $_server['remote_addr'];}
return preg_match(/[d.]{7,15}/, $ip, $matches) ? $matches[0] : false;
}
function is_ip($str) {
$ip = explode(., $str);if (count($ip)4) return 0;
foreach($ip as $ip_addr) {if ( !is_numeric($ip_addr) ) return 0;if ( $ip_addr255 ) return 0;
}return 1;
}
function ipdata($ip,$name=0)
{
$url=http://ip.taobao.com/service/getipinfo.php?ip=;
$data=json_decode(curl_file_get_contents($url.$ip)); $ipdata=$data->data;
if($name==all) {return $ipdata;}
else if($name==0){return $ipdata->country.$ipdata->region.$ipdata->city.$ipdata->isp;}
else if($name==1){return $ipdata->country;}
else if($name==2){return $ipdata->area;}
else if($name==3){return $ipdata->region;}
else if($name==4){return $ipdata->city;}
else if($name==5){return $ipdata->county;}
else if($name==6){return $ipdata->isp;}
}
?>
淘宝ip地址库接口说明
1. 请求接口(get):
http://ip.taobao.com/service/getipinfo.php?ip=[ip地址字串]
2. 响应信息:
(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商
3. 返回数据格式:
代码如下 复制代码
{code:0,data:{ip:210.75.225.254,country:u4e2du56fd,area:u534eu5317,
region:u5317u4eacu5e02,city:u5317u4eacu5e02,county:,isp:u7535u4fe1,
country_id:86,area_id:100000,region_id:110000,city_id:110000,
county_id:-1,isp_id:100017}}
其中code的值的含义为,0:成功,1:失败。
.htaccess 通用版伪静态规则 其它规则请参考下面的进行修改
代码如下 复制代码
rewriteengine on
rewriterule ^(.*)$ index.php?id=$1 [l]
sina sae专版伪静态配置规则
代码如下 复制代码
- rewrite: if (!is_dir() && !is_file() && path ~ /(.*) ) goto index.php?$1
永久链接:
转载随意!带上文章地址吧。