Rumah > pembangunan bahagian belakang > tutorial php > php查询ip地址来源归属地的脚本_PHP教程

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

WBOY
Lepaskan: 2016-07-13 10:31:52
asal
1175 orang telah melayarinya

<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>
Salin selepas log masuk

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/760054.htmlTechArticle? ('Content-Type:text/html;charset=utf-8' ( ['sub' = ['ip' = '' , (! = '请至少填写一个ip!' = ( ,'.' = ( ( != 3 || == || == -1 = '无效ip地址,请重新输入!' = ('h...
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan