Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $cache = new CPHPCache();
- $cache_time = 86500 * 30;
- $cache_id = $_SERVER['HTTP_X_REAL_IP'];
- $cache_path = '/SypexGeo/';
- if ($cache_time > 0 && $cache->InitCache($cache_time, $cache_id, $cache_path)) {
- $res = $cache->GetVars();
- if (is_object($res["GeoLocation"])) {
- $arResult['GeoLocation'] = $res["GeoLocation"];
- }
- }else{
- $is_bot = preg_match(
- "~(Google|Yahoo|Rambler|Bot|Yandex|Spider|Snoopy|Crawler|Finder|Mail|curl)~i",
- $_SERVER['HTTP_USER_AGENT']
- );
- if(!$is_bot)
- $geoResult = GeoIp\Manager::getDataResult(null, "ru");
- if ($geoResult) {
- if ($geoResult->isSuccess()) {
- $arResult['GeoLocation'] = $geoResult->getGeoData();
- }
- }
- if ($cache_time > 0) {
- $cache->StartDataCache($cache_time, $cache_id, $cache_path);
- $cache->EndDataCache(array("GeoLocation" => $arResult['GeoLocation']));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement