HomeLanguagesPHP | geoip_db_filename() Function

PHP | geoip_db_filename() Function

The geoip_db_filename() function is an inbuilt function in PHP, which is used to generate the filename for corresponding GeoIP database accepted as a parameter. The function will not indicate the existence of file on the disk instead will just return the filename where the library is searching the database.

Syntax:

string geoip_db_filename ( $database )

Parameter: This function accepts single parameter $database which is mandatory. The database type are integer. There are various predefined constants which are used as database listed below:

  • GEOIP_COUNTRY_EDITION
  • GEOIP_REGION_EDITION_REV0
  • GEOIP_CITY_EDITION_REV0
  • GEOIP_ORG_EDITION
  • GEOIP_ISP_EDITION
  • GEOIP_CITY_EDITION_REV1
  • GEOIP_REGION_EDITION_REV1
  • GEOIP_PROXY_EDITION
  • GEOIP_ASNUM_EDITION
  • GEOIP_NETSPEED_EDITION
  • GEOIP_DOMAIN_EDITION

The following constants are used for net speed:

  • GEOIP_UNKNOWN_SPEED
  • GEOIP_DIALUP_SPEED
  • GEOIP_CABLEDSL_SPEED
  • GEOIP_CORPORATE_SPEED

Return Value: This function returns the filename of the corresponding GeoIP database on success or NULL on failure/error.

Below programs illustrate the geoip_db_filename() function in PHP:

Program 1:




<?php
  
// PHP code implementing the geoip_db_filename() function 
  
// The function takes the database and returns
//  the filename according to the database
print geoip_db_filename(GEOIP_COUNTRY_EDITION);
?>


Output:

/usr/share/GeoIP/GeoIP.dat

Program 2:




<?php
$arr = array(
             'GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION,
             'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1,
             'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION,
             'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION,
             'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION,
             'EOIP_UNKNOWN_SPEED' => GEOIP_UNKNOWN_SPEED,
             'GEOIP_DIALUP_SPEED' => GEOIP_DIALUP_SPEED,
             'GEOIP_CABLEDSL_SPEED' => GEOIP_CABLEDSL_SPEED,
             'GEOIP_CORPORATE_SPEED' => GEOIP_CORPORATE_SPEED
             );
  
foreach ($arr as $val) {
    echo geoip_db_filename($val) . (geoip_db_avail($val) ? 'Available':'') . '<br>';
}
?>


Output:

/usr/share/GeoIP/GeoIP.datAvailable
/usr/share/GeoIP/GeoIPRegion.dat
/usr/share/GeoIP/GeoIPProxy.dat
/usr/share/GeoIP/GeoIPASNum.dat
/usr/share/GeoIP/GeoIPDomain.dat

/usr/share/GeoIP/GeoIP.datAvailable
/usr/share/GeoIP/GeoIPCity.dat
/usr/share/GeoIP/GeoIPRegion.dat

Related Articles:

Reference: http://php.net/manual/en/function.geoip-db-filename.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

5 COMMENTS

Most Popular

Dominic
32662 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7035 POSTS0 COMMENTS
Nicole Veronica
12174 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12262 POSTS0 COMMENTS
Shaida Kate Naidoo
7161 POSTS0 COMMENTS
Ted Musemwa
7427 POSTS0 COMMENTS
Thapelo Manthata
7126 POSTS0 COMMENTS
Umr Jansen
7127 POSTS0 COMMENTS