How to get the corresponding region and network type of IP in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:03:52
Original
1086 people have browsed it

PHP’s method of obtaining the IP corresponding to the region and using the network type

This article mainly introduces the method of PHP obtaining the IP corresponding to the region and using the network type. The example analyzes PHP by calling Tips for obtaining IP and network type from ip138 database. Friends who need it can refer to it

The example in this article describes how PHP obtains the IP corresponding region and uses the network type. Share it with everyone for your reference. The specific analysis is as follows:

During the test here, because the ip168 website was banned, I tried to modify the original code to use the data call of the ip138 database. The code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

//原程序有问题,现修改为ip138数据库

/**

* 获取IP地区

* Enter description here ...

* @param unknown_type $ip

*/

function GetArea($ip){

$url = "http://www.ip138.com/ips8.asp?ip=".$ip."&action=2";

$contents = file_get_contents($url);

preg_match_all('|

  • 本站主数据:.*
  • |',$contents,$rsR);

    $rsR[0][0] = str_replace("

  • 本站主数据:", "", $rsR[0][0]);

    $pos = strpos($rsR[0][0],'

  • ');

    $Area = substr_replace($rsR[0][0],'',$pos);

    return $Area;

    }

    header('Content-type:text/html;Charset=gb2312');

    $area = GetArea('218.242.232.194');

    print_r($area);

    ?>

    1 2

    3

    4 5

    67 8 9 10 11 12
    13
    14
    15 16 17 18 19 20
    Main data of this site: .*|',$contents,$rsR); $rsR[0][0] = str_replace("
  • Master data of this site:", "", $rsR[0][0]); $pos = strpos($rsR[0][0],'
  • '); $Area = substr_replace($rsR[0][0],'',$pos); return $Area; } header('Content-type:text/html;Charset=gb2312'); $area = GetArea('218.242.232.194'); print_r($area); ?>
    I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/966931.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966931.htmlTechArticlePHP obtains the IP corresponding region and uses the network type. This article mainly introduces the method of PHP obtaining the IP corresponding region and the use Network type method, the example analysis is that php obtains by calling the ip138 database...
    Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template