php71-geoip

Description:

PHP 7.1 geoip 확장. maxmind에서 제공하는 API와는 다른 버전이다.

Features:

function base sample codes:
1
<?php
2
$searches = array ('oops.org', 'kornet.net', 'yahoo.com');
3
4
try {
5
$g = GeoIP_open (GEOIP_MEMORY_CACHE|GEOIP_CHECK_CACHE);
6
if ( GeoIP_db_avail (GEOIP_CITY_EDITION_REV0) )
7
$gc = GeoIP_open (GEOIP_CITY_EDITION_REV0, GEOIP_INDEX_CACHE|GEOIP_CHECK_CACHE);
8
9
if ( GeoIP_db_avail (GEOIP_ISP_EDITION) )
10
$gi = GeoIP_open (GEOIP_ISP_EDITION, GEOIP_INDEX_CACHE|GEOIP_CHECK_CACHE);
11
12
if ( ! is_resource ($g) )
13
exit;
14
15
#echo "TYPE: " . geoip_database_info ($g) ."\n";
16
17
foreach ( $searches as $v ) {
18
$r = geoip_id_by_name ($g, $v);
19
print_r ($r);
20
21
if ( is_resource ($gc) ) {
22
$rc = GeoIP_record_by_name ($gc, $v);
23
print_r ($rc);
24
}
25
26
if ( is_resource ($gi) ) {
27
$ri = GeoIP_org_by_name ($gi, $v);
28
echo " $ri\n";
29
}
30
31
#echo "### " . geoip_country_code_by_name ($g, $v) . "\n";
32
#echo "### " . geoip_country_name_by_name ($g, $v) . "\n";
33
}
34
35
36
if ( is_resource ($gc) ) GeoIP_close ($gc);
37
if ( is_resource ($gi) ) GeoIP_close ($gi);
38
GeoIP_close ($g);
39
} catch ( GeoIPException $e ) {
40
fprintf (STDERR, "%s\n", $e->getMessage ());
41
$err = preg_split ('/\r?\n/', $e->getTraceAsString ());
42
print_r ($err);
43
}
44
?>
Copied!
OOP based codes:
1
<?php
2
$searches = array ('www.example.com', 'oops.org', 'kornet.net', 'yahoo.com');
3
4
try {
5
$g = new GeoIP (GEOIP_MEMORY_CACHE|GEOIP_CHECK_CACHE);
6
if ( GeoIP_db_avail (GEOIP_CITY_EDITION_REV0) )
7
$gc = new GeoIP (GEOIP_CITY_EDITION_REV0, GEOIP_INDEX_CACHE|GEOIP_CHECK_CACHE);
8
if ( GeoIP_db_avail (GEOIP_ISP_EDITION) )
9
$gi = new GeoIP (GEOIP_ISP_EDITION, GEOIP_INDEX_CACHE|GEOIP_CHECK_CACHE);
10
11
#echo "TYPE: " . $g->database_info () ."\n";
12
13
foreach ( $searches as $v ) {
14
$r = $g->id_by_name ($v);
15
print_r ($r);
16
17
if ( GeoIP_db_avail (GEOIP_CITY_EDITION_REV0) ) {
18
$rc = $gc->record_by_name ($v);
19
print_r ($rc);
20
}
21
22
if ( GeoIP_db_avail (GEOIP_ISP_EDITION) ) {
23
$ri = $gi->org_by_name ($v);
24
echo "ISP NAME: $ri\n";
25
}
26
27
#echo "### " . $g->country_code_by_name ($v) . "\n";
28
#echo "### " . $g->country_name_by_name ($v) . "\n";
29
}
30
} catch ( GeoIPException $e ) {
31
fprintf (STDERR, "%s\n", $e->getMessage ());
32
$err = preg_split ('/\r?\n/', $e->getTraceAsString ());
33
print_r ($err);
34
}
35
?>
Copied!

Reference:

Dependencies:

Sub Packages:

  • None

Releated Packages:

  • None
Last modified 2yr ago