dolibarr 25.0.0-alpha
DolGeoIP Class Reference

Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeFromIP($ip); $geoip->close();. More...

Public Member Functions

 __construct ($type, $datfile)
 Constructor.
 
 getCityNameFromIP ($ip)
 Return the city name from an ip.
 
 getCountryCodeFromIP ($ip)
 Return in lower case the country code from an ip.
 
 getCountryCodeFromName ($name)
 Return in lower case the country code from a host name.
 
 getVersion ()
 Return version of data file.
 
 close ()
 Close geoip object.
 

Private Member Functions

 getGeoIp2IsoCode ($ipOrName)
 Return the ISO country code for an IP or a host name using the embedded GeoIP2 reader.
 
 getGeoIp2CityName ($ipOrName)
 Return the city name for an IP or a host name using the embedded GeoIP2 reader.
 

Detailed Description

Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeFromIP($ip); $geoip->close();.

Definition at line 36 of file dolgeoip.class.php.

Constructor & Destructor Documentation

◆ __construct()

DolGeoIP::__construct ( $type,
$datfile )

Constructor.

Parameters
'country'|'city'$type 'country' or 'city'
string$datfileData file

Definition at line 59 of file dolgeoip.class.php.

References dol_syslog(), and getDolGlobalString().

Member Function Documentation

◆ close()

DolGeoIP::close ( )

Close geoip object.

Returns
void

Definition at line 303 of file dolgeoip.class.php.

◆ getCityNameFromIP()

DolGeoIP::getCityNameFromIP ( $ip)

Return the city name from an ip.

Only works if the configured datafile is a City database.

Parameters
string$ipIP to scan
Returns
string City name, or '' if not found or if the datafile is a Country-only database

Definition at line 190 of file dolgeoip.class.php.

References getDolGlobalString(), and getGeoIp2CityName().

◆ getCountryCodeFromIP()

DolGeoIP::getCountryCodeFromIP ( $ip)

Return in lower case the country code from an ip.

Parameters
string$ipIP to scan
Returns
string Country code (two letters)

Definition at line 213 of file dolgeoip.class.php.

References getDolGlobalString(), and getGeoIp2IsoCode().

◆ getCountryCodeFromName()

DolGeoIP::getCountryCodeFromName ( $name)

Return in lower case the country code from a host name.

Parameters
string$nameFQN of host (example: myserver.xyz.com)
Returns
string Country code (two letters)

Definition at line 257 of file dolgeoip.class.php.

References getDolGlobalString(), and getGeoIp2IsoCode().

◆ getGeoIp2CityName()

DolGeoIP::getGeoIp2CityName ( $ipOrName)
private

Return the city name for an IP or a host name using the embedded GeoIP2 reader.

Only returns something when the configured datafile is a City-type database (a Country-type database has no city record at all).

Parameters
string$ipOrNameIP address or host name to look up
Returns
string City name (best available locale) or '' if not found or not a City database

Definition at line 166 of file dolgeoip.class.php.

Referenced by getCityNameFromIP().

◆ getGeoIp2IsoCode()

DolGeoIP::getGeoIp2IsoCode ( $ipOrName)
private

Return the ISO country code for an IP or a host name using the embedded GeoIP2 reader.

A Country database is read with country(), but a City database (which also embeds the country record) is read with city(), so a City datafile configured as the country datafile still resolves instead of failing with a BadMethodCallException.

Parameters
string$ipOrNameIP address or host name to look up
Returns
string Country code (two letters, upper case) or '' if not found

Definition at line 138 of file dolgeoip.class.php.

Referenced by getCountryCodeFromIP(), and getCountryCodeFromName().

◆ getVersion()

DolGeoIP::getVersion ( )

Return version of data file.

Returns
string Version of datafile

Definition at line 280 of file dolgeoip.class.php.

References getDolGlobalString().


The documentation for this class was generated from the following file: