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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
?>

chevron_right


Output:

/usr/share/GeoIP/GeoIP.dat

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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>';
}
?>

chevron_right


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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.