Advertisement
denorian

Untitled

Jan 19th, 2018
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. $cache = new CPHPCache();
  2. $cache_time = 86500 * 30;
  3. $cache_id = $_SERVER['HTTP_X_REAL_IP'];
  4. $cache_path = '/SypexGeo/';
  5. if ($cache_time > 0 && $cache->InitCache($cache_time, $cache_id, $cache_path)) {
  6. $res = $cache->GetVars();
  7. if (is_object($res["GeoLocation"])) {
  8. $arResult['GeoLocation'] = $res["GeoLocation"];
  9. }
  10. }else{
  11. $is_bot = preg_match(
  12. "~(Google|Yahoo|Rambler|Bot|Yandex|Spider|Snoopy|Crawler|Finder|Mail|curl)~i",
  13. $_SERVER['HTTP_USER_AGENT']
  14. );
  15. if(!$is_bot)
  16. $geoResult = GeoIp\Manager::getDataResult(null, "ru");
  17. if ($geoResult) {
  18. if ($geoResult->isSuccess()) {
  19. $arResult['GeoLocation'] = $geoResult->getGeoData();
  20. }
  21. }
  22. if ($cache_time > 0) {
  23. $cache->StartDataCache($cache_time, $cache_id, $cache_path);
  24. $cache->EndDataCache(array("GeoLocation" => $arResult['GeoLocation']));
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement