'MT', 'in_european_union' => 1, 'country_confirmed' => 0)); } // cache response $cacheFileDir = $_SERVER['TMPDIR'].'/cache/'.substr($client_ip, 0, strpos($client_ip, '.', strpos($client_ip, '.') + 1) ); $cacheFile = $cacheFileDir.'/'.$client_ip; if (!file_exists($cacheFileDir)) { umask(0077); mkdir($cacheFileDir); } if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) > (86400 * 10)) { unlink($cacheFile); } elseif (file_exists($cacheFile)) { $geoLocData = json_decode(file_get_contents($cacheFile),true); return($geoLocData); } // UM end $credentials = 'Authorization: Basic ' . base64_encode(ACCOUNT_ID . ':' . LICENSE_KEY); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://geolite.info/geoip/v2.1/city/{$client_ip}", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( $credentials ), )); $response = curl_exec($curl); curl_close($curl); $geo_data = json_decode($response); //UM VERY TEMP - fallback to be replaced!! if ( isset($geo_data->code) AND $geo_data->code == "INSUFFICIENT_FUNDS") { $credentials = 'Authorization: Basic ' . base64_encode('866967' . ':' . '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'); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://geolite.info/geoip/v2.1/city/{$client_ip}", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( $credentials ), )); $response = curl_exec($curl); curl_close($curl); $geo_data = json_decode($response); } //UM END VERY TEMP if (isset($geo_data->country->iso_code)) { $geoLocData = array(); $geoLocData['country_code'] = $geo_data->country->iso_code; if (isset($geo_data->country->is_in_european_union) && $geo_data->country->is_in_european_union) { $geoLocData['in_european_union'] = 1; } else { $geoLocData['in_european_union'] = 0; } $geoLocData['country_confirmed'] = 0; } // UM begin umask(0077); file_put_contents($cacheFile, json_encode($geoLocData), LOCK_EX); //UM end return $geoLocData; } function getRealIP() { $headers = array ('HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM', 'HTTP_CLIENT_IP' ); foreach ( $headers as $header ) { if (isset ( $_SERVER [$header] )) { if (($pos = strpos ( $_SERVER [$header], ',' )) != false) { $ip = substr ( $_SERVER [$header], 0, $pos ); } else { $ip = $_SERVER [$header]; } $ipnum = ip2long ( $ip ); if ($ipnum !== - 1 && $ipnum !== false && (long2ip ( $ipnum ) === $ip)) { if (($ipnum - 184549375) && // Not in 10.0.0.0/8 ($ipnum - 1407188993) && // Not in 172.16.0.0/12 ($ipnum - 1062666241)) // Not in 192.168.0.0/16 if (($pos = strpos ( $_SERVER [$header], ',' )) != false) { $ip = substr ( $_SERVER [$header], 0, $pos ); } else { $ip = $_SERVER [$header]; } return $ip; } } } return $_SERVER ['REMOTE_ADDR']; } function reloadPage() { echo ""; } ?>