首頁  >  文章  >  後端開發  >  PHP取得ip對應地區和使用的網路類型

PHP取得ip對應地區和使用的網路類型

WBOY
WBOY原創
2016-07-25 09:09:061135瀏覽
看到
http://www.oschina.net/code/snippet_106370_5983
这篇文章,测试的时候因为ip168网站禁止,所以试着在原有代码上修改为ip138数据库的数据调用

  1. //原程序有问题,现修改为ip138数据库
  2. /**
  3. * 获取IP地区
  4. * Enter description here ...
  5. * @param unknown_type $ip
  6. */
  7. function GetArea($ip){
  8. $url = "http://www.ip138.com/ips8.asp?ip=".$ip."&action=2";
  9. $contents = file_get_contents($url);
  10. preg_match_all('|
  11. 本站主数据:.*
  12. |',$contents,$rsR);
  13. $rsR[0][0] = str_replace("
  14. 本站主数据:", "", $rsR[0][0]);
  15. $pos = strpos($rsR[0][0],'
  16. ');
  17. $Area = substr_replace($rsR[0][0],'',$pos);
  18. return $Area;
  19. }
  20. header('Content-type:text/html;Charset=gb2312');
  21. $area = GetArea('218.242.232.194');
  22. print_r($area);
  23. ?>
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn