49 if (!empty($conf->global->GEOIP_VERSION)) {
50 $geoipversion = $conf->global->GEOIP_VERSION;
53 if ($type ==
'country') {
55 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
56 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
58 } elseif ($type ==
'city') {
60 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
61 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
64 print
'ErrorBadParameterInConstructor';
69 if (empty($type) || empty($datfile)) {
70 $this->errorlabel =
'Constructor was called with no datafile parameter';
71 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
74 if (!file_exists($datfile) || !is_readable($datfile)) {
75 $this->error =
'ErrorGeoIPClassNotInitialized';
76 $this->errorlabel =
"Datafile ".$datfile.
" not found";
77 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
81 if ($geoipversion ==
'2') {
83 $this->gi =
new GeoIp2\Database\Reader($datfile);
85 $this->error = $e->getMessage();
86 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
89 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
90 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
91 } elseif (function_exists(
'geoip_country_code_by_name')) {
111 if (!empty($conf->global->GEOIP_VERSION)) {
112 $geoipversion = $conf->global->GEOIP_VERSION;
115 if (empty($this->gi)) {
118 if ($this->gi ==
'NOGI') {
120 return strtolower(geoip_country_code_by_name($ip));
122 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
123 if ($geoipversion ==
'2') {
125 $record = $this->gi->country($ip);
126 return strtolower($record->country->isoCode);
132 if (!function_exists(
'geoip_country_code_by_addr')) {
133 return strtolower(geoip_country_code_by_name($ip));
135 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
138 if ($geoipversion ==
'2') {
140 $record = $this->gi->country($ip);
141 return strtolower($record->country->isoCode);
147 if (!function_exists(
'geoip_country_code_by_addr_v6')) {
148 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
150 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
167 if (!empty($conf->global->GEOIP_VERSION)) {
168 $geoipversion = $conf->global->GEOIP_VERSION;
171 if (empty($this->gi)) {
175 if ($geoipversion ==
'2') {
177 $record = $this->gi->country($name);
178 return $record->country->isoCode;
184 return strtolower(geoip_country_code_by_name($name));
198 if (!empty($conf->global->GEOIP_VERSION)) {
199 $geoipversion = $conf->global->GEOIP_VERSION;
202 if ($geoipversion ==
'php') {
203 if ($this->gi ==
'NOGI') {
204 return geoip_database_info();
206 return 'geoip_database_info() function not available';
210 return 'Not available (not using PHP internal geo functions - We are using embedded Geoip v'.$geoipversion.
')';
220 if (function_exists(
'geoip_close')) {
222 geoip_close($this->gi);
Classe to manage GeoIP Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeFromIP($ip)...
getCountryCodeFromIP($ip)
Return in lower case the country code from an ip.
__construct($type, $datfile)
Constructor.
getVersion()
Return verion of data file.
close()
Close geoip object.
getCountryCodeFromName($name)
Return in lower case the country code from a host name.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.