<?php header("content-type: text/html; charset=utf-8"); //获取ip地址的方法 function getip(){ if (isset($_server)) { if (isset($_server['http_x_forwarded_for'])) { $realip = $_server['http_x_forwarded_for']; } elseif (isset($_server['http_client_ip'])) { $realip = $_server['http_client_ip']; } else { $realip = $_server['remote_addr']; } } else { if (getenv("http_x_forwarded_for")) { $realip = getenv( "http_x_forwarded_for"); } elseif (getenv("http_client_ip")) { $realip = getenv("http_client_ip"); } else { $realip = getenv("remote_addr"); } } return $realip; } echo $ip = getip();//通过php的file_get_contents()方法获取地理位置//新浪接口根据ip查询所在区域信息$res0 = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip");$res0 = json_decode($res0,true);print_r($res0);echo "<br/>";//淘宝接口根据ip查询所在区域信息$res1 = file_get_contents("http://ip.taobao.com/service/getipinfo.php?ip=$ip");$res1 = json_decode($res1,true);print_r($res1);echo "<br/>";//通过php的curl获取地理位置//新浪根据ip获取地理位置api $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip'; $ch = curl_init($url); curl_setopt($ch,curlopt_encoding ,'utf8'); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_returntransfer, true) ; // 获取数据返回 $location = curl_exec($ch); $location = json_decode($location); print_r($location); curl_close($ch); $loc = ""; if($location===false) return ""; if (empty($location->desc)) { $loc = $location->province.$location->city.$location->district.$location->isp; }else{ $loc = $location->desc; } echo $loc; //腾讯根据ip获取地理位置api $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1=$ip'; $ch = curl_init($url); curl_setopt($ch,curlopt_encoding ,'gb2312'); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_returntransfer, true) ; // 获取数据返回 $result = curl_exec($ch); $result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码 curl_close($ch); preg_match("@<span>(.*)</span></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1584">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680266797527.png" alt="钉钉 AI 助理">
</a>
<div class="aritcle_card_info">
<a href="/ai/1584">钉钉 AI 助理</a>
<p>钉钉AI助理汇集了钉钉AI产品能力,帮助企业迈入智能新时代。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="钉钉 AI 助理">
<span>21</span>
</div>
</div>
<a href="/ai/1584" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="钉钉 AI 助理">
</a>
</div>
@iU",$result,$ipArray); $loc = $ipArray[1]; echo $loc;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号