> php教程 > php手册 > php查询ip地址来源归属地的脚本

php查询ip地址来源归属地的脚本

WBOY
풀어 주다: 2016-06-13 09:37:13
원래의
807명이 탐색했습니다.

<span  1</span> <?<span php
</span><span  2</span>     <span header</span>('Content-Type:text/html;charset=utf-8'<span );
</span><span  3</span>     
<span  4</span>     <span if</span>(<span $_GET</span>['sub'<span ]){
</span><span  5</span>         <span $ip</span> = <span $_GET</span>['ip'<span ];
</span><span  6</span>         <span $msg</span> = ''<span ;
</span><span  7</span> <span         ipSearch();
</span><span  8</span> <span     }
</span><span  9</span>     
<span 10</span>     <span function</span><span  ipSearch(){
</span><span 11</span>         <span global</span> <span $ip</span>,<span $msg</span><span ;
</span><span 12</span>         <span if</span>(!<span $ip</span><span ){
</span><span 13</span>             <span $msg</span> = '请至少填写一个ip!'<span ;
</span><span 14</span>             <span return</span><span ;
</span><span 15</span> <span         }
</span><span 16</span>         <span $arises</span> = <span substr_count</span>(<span $ip</span>,'.'<span );
</span><span 17</span>         <span $long</span> = <span ip2long</span>(<span $ip</span><span );
</span><span 18</span>         <span if</span>(<span $arises</span> != 3 || <span $long</span> == <span false</span> || <span $long</span>== -1<span ){
</span><span 19</span>             <span $msg</span> = '无效ip地址,请重新输入!'<span ;
</span><span 20</span>             <span return</span><span ;
</span><span 21</span> <span         }
</span><span 22</span>         <span $content</span> = <span file_get_contents</span>('http://www.ip138.com/ips1388.asp?action=2&ip='.<span $ip</span><span );
</span><span 23</span>         <span $content</span> = <span iconv</span>('gb2312', 'utf-8', <span $content</span><span );
</span><span 24</span>         <span $pos</span> = <span stripos</span>(<span $content</span>, '<li>本站主数据'<span );
</span><span 25</span>         <span if</span>(!<span $pos</span><span ){
</span><span 26</span>             <span $msg</span> = '没有查询到!'<span ;
</span><span 27</span>             <span return</span><span ;
</span><span 28</span> <span         }
</span><span 29</span>         <span $endPos</span> = <span stripos</span>(<span $content</span>, '</li>', <span $pos</span><span );
</span><span 30</span>         <span $jumpLen</span> = <span strlen</span>('<li>本站主数据:'<span );
</span><span 31</span>         <span $address</span> = <span substr</span>(<span $content</span>, <span $pos</span>+<span $jumpLen</span>, <span $endPos</span>-<span $pos</span>-<span $jumpLen</span><span );
</span><span 32</span>         <span $msg</span> = <span $address</span><span ;
</span><span 33</span>         <span return</span><span ;
</span><span 34</span> <span     }
</span><span 35</span>     
<span 36</span> ?><!DOCTYPE html>
<span 37</span> <html>
<span 38</span> <head>
<span 39</span>     <meta charset="utf-8">
<span 40</span>     <title>test</title>
<span 41</span> </head>
<span 42</span> <body>
<span 43</span>     <form method="get">
<span 44</span>         <input type="text" name="ip" />
<span 45</span>         <input type="submit" value="search" name="sub" />
<span 46</span>     </form><br />
<span 47</span>     <?php <span echo</span> <span $msg</span>; ?>
<span 48</span> </body>
<span 49</span> </html>
로그인 후 복사

 

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿