56 $geoipversion = $conf->global->GEOIP_VERSION;
59 if ($type ==
'country') {
61 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
62 if (function_exists(
'stream_wrapper_restore')) {
63 stream_wrapper_restore(
'phar');
65 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
67 } elseif ($type ==
'city') {
69 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
70 if (function_exists(
'stream_wrapper_restore')) {
71 stream_wrapper_restore(
'phar');
73 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
76 print
'ErrorBadParameterInConstructor';
81 if (empty($type) || empty($datfile)) {
82 $this->errorlabel =
'Constructor was called with no datafile parameter';
83 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
86 if (!file_exists($datfile) || !is_readable($datfile)) {
87 $this->error =
'ErrorGeoIPClassNotInitialized';
88 $this->errorlabel =
"Datafile ".$datfile.
" not found";
89 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
93 if ($geoipversion ==
'2') {
96 $this->gi =
new GeoIp2\Database\Reader($datfile);
98 $this->error = $e->getMessage();
99 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
102 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
103 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
104 } elseif (function_exists(
'geoip_country_code_by_name')) {
125 $geoipversion = $conf->global->GEOIP_VERSION;
128 if (empty($this->gi)) {
131 if ($this->gi ==
'NOGI') {
133 return strtolower(geoip_country_code_by_name($ip));
135 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
136 if ($geoipversion ==
'2') {
138 $record = $this->gi->country($ip);
139 return strtolower($record->country->isoCode);
145 if (!function_exists(
'geoip_country_code_by_addr')) {
146 return strtolower(geoip_country_code_by_name($ip));
148 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
151 if ($geoipversion ==
'2') {
153 $record = $this->gi->country($ip);
154 return strtolower($record->country->isoCode);
160 if (function_exists(
'geoip_country_code_by_addr_v6')) {
161 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
162 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
163 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));