52 if (!empty($conf->global->GEOIP_VERSION)) {
53 $geoipversion = $conf->global->GEOIP_VERSION;
56 if ($type ==
'country') {
58 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
59 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
61 } elseif ($type ==
'city') {
63 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
64 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
67 print
'ErrorBadParameterInConstructor';
72 if (empty($type) || empty($datfile)) {
73 $this->errorlabel =
'Constructor was called with no datafile parameter';
74 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
77 if (!file_exists($datfile) || !is_readable($datfile)) {
78 $this->error =
'ErrorGeoIPClassNotInitialized';
79 $this->errorlabel =
"Datafile ".$datfile.
" not found";
80 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
84 if ($geoipversion ==
'2') {
86 $this->gi =
new GeoIp2\Database\Reader($datfile);
88 $this->error = $e->getMessage();
89 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
92 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
93 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
94 } elseif (function_exists(
'geoip_country_code_by_name')) {
114 if (!empty($conf->global->GEOIP_VERSION)) {
115 $geoipversion = $conf->global->GEOIP_VERSION;
118 if (empty($this->gi)) {
121 if ($this->gi ==
'NOGI') {
123 return strtolower(geoip_country_code_by_name($ip));
125 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
126 if ($geoipversion ==
'2') {
128 $record = $this->gi->country($ip);
129 return strtolower($record->country->isoCode);
135 if (!function_exists(
'geoip_country_code_by_addr')) {
136 return strtolower(geoip_country_code_by_name($ip));
138 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
141 if ($geoipversion ==
'2') {
143 $record = $this->gi->country($ip);
144 return strtolower($record->country->isoCode);
150 if (function_exists(
'geoip_country_code_by_addr_v6')) {
151 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
152 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
153 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
172 if (!empty($conf->global->GEOIP_VERSION)) {
173 $geoipversion = $conf->global->GEOIP_VERSION;
176 if (empty($this->gi)) {
180 if ($geoipversion ==
'2') {
182 $record = $this->gi->country($name);
183 return $record->country->isoCode;
189 return strtolower(geoip_country_code_by_name($name));