67 if ($type ==
'country') {
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';
75 } elseif ($type ==
'city') {
77 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
78 if (function_exists(
'stream_wrapper_restore')) {
79 stream_wrapper_restore(
'phar');
81 require_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
84 print
'ErrorBadParameterInConstructor';
89 if (empty($type) || empty($datfile)) {
90 $this->errorlabel =
'Constructor was called with no datafile parameter';
91 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
94 if (!file_exists($datfile) || !is_readable($datfile)) {
95 $this->error =
'ErrorGeoIPClassNotInitialized';
96 $this->errorlabel =
"Datafile ".$datfile.
" not found";
97 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
101 if ($geoipversion ==
'2') {
104 $this->gi =
new GeoIp2\Database\Reader($datfile);
106 $this->error = $e->getMessage();
107 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
110 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
111 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
112 } elseif (function_exists(
'geoip_country_code_by_name')) {
136 if (empty($this->gi)) {
139 if ($this->gi ==
'NOGI') {
141 return strtolower(geoip_country_code_by_name($ip));
143 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
144 if ($geoipversion ==
'2') {
146 $record = $this->gi->country($ip);
147 return strtolower($record->country->isoCode);
153 if (!function_exists(
'geoip_country_code_by_addr')) {
154 return strtolower(geoip_country_code_by_name($ip));
156 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
159 if ($geoipversion ==
'2') {
161 $record = $this->gi->country($ip);
162 return strtolower($record->country->isoCode);
168 if (function_exists(
'geoip_country_code_by_addr_v6')) {
169 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
170 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
171 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));