发现之前有一个脚本没有写完,简单扩充了一下。
获取IP使用的是经典的逻辑,地理定位使用的是SINA的通用接口。
使用方法详见源码:
复制代码 代码如下:
<"GBK//IGNORE","UTF-8",$return);
}
if(isset($this->args['ECHO'])&&$this->args['ECHO']==true){
echo$return;
returntrue;
}else{
return$return;
}
}
}
public functioninit_args($args)
{
$result=array();
for($i=0,$n=count($args);$i<$n;$i++){
$result=self::associative_push($args[$i],$result);
}
return$result;
}
public functionassociative_push($arr,$tmp)
{
if(is_array($tmp)){
foreach($tmpas$key=>$value){
$arr[$key]=$value;
}
return$arr;
}
returnfalse;
}
public functionGetIP()
{
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])&&$_SERVER['HTTP_X_FORWARDED_FOR']&&strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'],'unknown')){
return$_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')){
return$_SERVER['REMOTE_ADDR'];
}
}
private functionipCURL($url)
{
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
ob_start();
curl_exec($ch);
curl_close($ch);
$result=ob_get_contents();
ob_end_clean();
return$result;
}
}
"utf8">
<title>demo</title>
<script type="text/javascript">
varip="<";
vardata=<"\n";
}
alert(result+ip);
</script>
</head>
<body>
<h1>CODE:</h1>
<h2>GETIP</h2>
<p>'ONLYIP'=>true,'ECHO'=>true</p>
<p><?phpnewIP(array('ONLYIP'=>true,'ECHO'=>true));?></p>
<P>'ONLYIP'=>true,'FORMAT'=>'JSON','ECHO'=>true</P>
<p><?phpnewIP(array('ONLYIP'=>true,'FORMAT'=>'JSON','ECHO'=>true));?></p>
<h2>GET Location</h2>
<p>'ECHO'=>true</p>
<p><?phpnewIP(array('ECHO'=>true));?></p>
<p>'FORMAT'=>'JSON','ECHO'=>true</p>
<p><?php newIP(array('FORMAT'=>'JSON','ECHO'=>true));?></p>
</body>
</html>
PHP,获取IP,获取地理位置
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com