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_addr_v6($this->gi, $ip));
149 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
150 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
169 if (!empty($conf->global->GEOIP_VERSION)) {
170 $geoipversion = $conf->global->GEOIP_VERSION;
173 if (empty($this->gi)) {
177 if ($geoipversion ==
'2') {
179 $record = $this->gi->country($name);
180 return $record->country->isoCode;
186 return strtolower(geoip_country_code_by_name($name));
200 if (!empty($conf->global->GEOIP_VERSION)) {
201 $geoipversion = $conf->global->GEOIP_VERSION;
204 if ($geoipversion ==
'php') {
205 if ($this->gi ==
'NOGI') {
206 return geoip_database_info();
208 return 'geoip_database_info() function not available';
212 return 'Not available (not using PHP internal geo functions - We are using embedded Geoip v'.$geoipversion.
')';
222 if (function_exists(
'geoip_close')) {
224 geoip_close($this->gi);