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 include_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 include_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
84 print
'ErrorBadParameterInConstructor';
88 $this->error = $e->getMessage();
89 $this->errorlabel =
'Exception '.$this->error;
90 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
95 if (empty($type) || empty($datfile)) {
96 $this->errorlabel =
'Constructor was called with no datafile parameter';
97 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
100 if (!file_exists($datfile) || !is_readable($datfile)) {
101 $this->error =
'ErrorGeoIPClassNotInitialized';
102 $this->errorlabel =
"Datafile ".$datfile.
" not found";
103 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
107 if ($geoipversion ==
'2') {
110 $this->gi =
new GeoIp2\Database\Reader($datfile);
112 $this->error = $e->getMessage();
113 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
116 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
117 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
118 } elseif (function_exists(
'geoip_country_code_by_name')) {
142 if (empty($this->gi)) {
145 if ($this->gi ==
'NOGI') {
147 return strtolower(geoip_country_code_by_name($ip));
149 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
150 if ($geoipversion ==
'2') {
152 $record = $this->gi->country($ip);
153 return strtolower($record->country->isoCode);
159 if (!function_exists(
'geoip_country_code_by_addr')) {
160 return strtolower(geoip_country_code_by_name($ip));
162 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
165 if ($geoipversion ==
'2') {
167 $record = $this->gi->country($ip);
168 return strtolower($record->country->isoCode);
174 if (function_exists(
'geoip_country_code_by_addr_v6')) {
175 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
176 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
177 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));