Home  >  Article  >  Backend Development  >  PHP obtains the corresponding region of the IP and the network type used

PHP obtains the corresponding region of the IP and the network type used

WBOY
WBOYOriginal
2016-07-25 09:09:061184browse
See
http://www.oschina.net/code/snippet_106370_5983
This article was tested because the ip168 website was banned, so I tried to modify the original code to use the data call of the ip138 database.

  1. //There is a problem with the original program, now it is modified to ip138 database
  2. /**
  3. * Get IP region
  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. Main data of this site: .*|',$contents,$rsR);
  12. $rsR[0][0] = str_replace("
  13. Main data of this site:", "", $rsR[0][0]);
  14. $pos = strpos($rsR[0][0],'
  15. ');
  16. $Area = substr_replace($rsR[0][0],'',$pos);
  17. return $Area;
  18. }
  19. header('Content-type:text/html;Charset=gb2312');
  20. $area = GetArea('218.242.232.194');
  21. print_r($area);
  22. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn