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 stream_wrapper_restore(
'phar');
60 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
62 } elseif ($type ==
'city') {
64 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
65 stream_wrapper_restore(
'phar');
66 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
69 print
'ErrorBadParameterInConstructor';
74 if (empty($type) || empty($datfile)) {
75 $this->errorlabel =
'Constructor was called with no datafile parameter';
76 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
79 if (!file_exists($datfile) || !is_readable($datfile)) {
80 $this->error =
'ErrorGeoIPClassNotInitialized';
81 $this->errorlabel =
"Datafile ".$datfile.
" not found";
82 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
86 if ($geoipversion ==
'2') {
88 $this->gi =
new GeoIp2\Database\Reader($datfile);
90 $this->error = $e->getMessage();
91 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
94 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
95 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
96 } elseif (function_exists(
'geoip_country_code_by_name')) {
116 if (!empty($conf->global->GEOIP_VERSION)) {
117 $geoipversion = $conf->global->GEOIP_VERSION;
120 if (empty($this->gi)) {
123 if ($this->gi ==
'NOGI') {
125 return strtolower(geoip_country_code_by_name($ip));
127 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
128 if ($geoipversion ==
'2') {
130 $record = $this->gi->country($ip);
131 return strtolower($record->country->isoCode);
137 if (!function_exists(
'geoip_country_code_by_addr')) {
138 return strtolower(geoip_country_code_by_name($ip));
140 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
143 if ($geoipversion ==
'2') {
145 $record = $this->gi->country($ip);
146 return strtolower($record->country->isoCode);
152 if (function_exists(
'geoip_country_code_by_addr_v6')) {
153 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
154 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
155 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
174 if (!empty($conf->global->GEOIP_VERSION)) {
175 $geoipversion = $conf->global->GEOIP_VERSION;
178 if (empty($this->gi)) {
182 if ($geoipversion ==
'2') {
184 $record = $this->gi->country($name);
185 return $record->country->isoCode;
191 return strtolower(geoip_country_code_by_name($name));
205 if (!empty($conf->global->GEOIP_VERSION)) {
206 $geoipversion = $conf->global->GEOIP_VERSION;
209 if ($geoipversion ==
'php') {
210 if ($this->gi ==
'NOGI') {
211 return geoip_database_info();
213 return 'geoip_database_info() function not available';
217 return 'Not available (not using PHP internal geo functions - We are using embedded Geoip v'.$geoipversion.
')';
227 if (function_exists(
'geoip_close')) {
229 geoip_close($this->gi);