Example #1
0
function IPDATA($ip)
{
    require_once "ipgeobase.php";
    $gb = new IPGeoBase();
    $data = $gb->getRecord($ip);
    return $data['city'];
    /*
    array(7) {
      ["range"]=>
      string(27) "46.46.128.0 - 46.46.169.255"
      ["cc"]=>
      string(2) "RU"
      ["city"]=>
      string(6) "Москва"
      ["region"]=>
      string(6) "Москва"
      ["district"]=>
      string(29) "Центральный федеральный округ"
      ["lat"]=>
      string(9) "55.755787"
      ["lng"]=>
      string(9) "37.617634"
    }
    */
}
Example #2
0
function userRegion()
{
    $gb = new IPGeoBase();
    $region = "";
    if (($data = $gb->getRecord(getenv('REMOTE_ADDR'))) && ($data['city'] || $data['region'])) {
        $region .= "Регион: " . iconv('windows-1251', 'utf-8', $data['city']);
        if ($data['city'] && $data['region']) {
            $region .= ', ';
        }
        if ($data['region']) {
            $region .= iconv('windows-1251', 'utf-8', $data['region']);
        }
        $region .= ' (ip-адрес ' . getenv('REMOTE_ADDR') . ')';
    }
    return $region;
}
Example #3
0
 /**
  * @param string $ip
  * @return mixed
  */
 public function getRecord($ip = null)
 {
     if ($ip === null) {
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     }
     if (!isset(self::$cacheIp[$ip])) {
         $result = parent::getRecord($ip);
         if (is_array($result)) {
             foreach ($result as $key => $value) {
                 $result[$key] = Encoding::convertEncoding($value, 'windows-1251', SITE_CHARSET);
             }
         }
         self::$cacheIp[$ip] = $result;
     }
     return self::$cacheIp[$ip];
 }
function getGeoLocation($ip)
{
    global $arGeoCodes;
    //GeoIP
    require_once dirname(__FILE__) . "/geoip/geoip.inc";
    require_once dirname(__FILE__) . "/geoip/geoipcity.inc";
    //GeoLite City
    require_once dirname(__FILE__) . "/geoip/geoipregionvars.php";
    require_once dirname(__FILE__) . "/geoipregionvars.ru.php";
    //перезаписываем русскими названиями RU и UA
    //IpGeoBase
    require_once dirname(__FILE__) . "/ipgeobase.php";
    $gi = geoip_open(dirname(__FILE__) . "/GeoLiteCity.dat", GEOIP_STANDARD);
    $gb = new IPGeoBase();
    $country = $region = $city = '';
    $data = $gb->getRecord($ip);
    if ($data) {
        /*foreach($data as &$v)
          {
              $v = iconv('windows-1251', 'utf-8', $v);
          }
          unset($v);*/
        $country = !empty($data['cc']) ? $arGeoCodes[$data['cc']] : '';
        $region = !empty($data['region']) ? $data['region'] : '';
        $city = !empty($data['city']) ? $data['city'] : '';
    }
    if (!in_array($data['cc'], array('RU', 'UA'))) {
        $record = geoip_record_by_addr($gi, $ip);
        if ($record) {
            $country = !empty($record->country_code) ? $arGeoCodes[$record->country_code] : '';
            $region = isset($GEOIP_REGION_NAME[$record->country_code][$record->region]) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : $record->region;
            $city = $record->city;
            geoip_close($gi);
        }
    }
    if ($country) {
        return array('country' => $country, 'region' => $region, 'city' => $city);
    } else {
        return false;
    }
}
Example #5
0
File: main.php Project: dimakos/myj
<noindex>
<div class="main">
	<center>
	<img class="mainlogo" src="/images/mainlogo.png">
	<div class="slogantop">Социальная сеть, которая объединяет вас<br>и ваших домашних мастеров</div>
	<p class="margin">Выбери свой город</p>
	
	<?php 
require_once "ipgeobase/ipgeobase.php";
$gb = new IPGeoBase();
$data = $gb->getRecord($_SERVER["REMOTE_ADDR"]);
$region = $data['region'];
$city = $data['city'];
?>
	
	<div class="searchform">
		<input type="text" id="search_from_place" class="search_form" value="<?php 
echo $city;
?>
">
	</div>
	
	<p class="margin">Выберите специализацию, в которой вы ищете мастера</p>
	
	<div class="iconsblock">		
		<div class="icon">
				<img class="floatleft" src="/images/santehnik-1.png">			
			<a href="/santehnik/" target="blank">
			<img class="iconhover"  src="/images/santehnik-hover.png">
			</a>
			<p class="icontitle">Сантехник</p>						
Example #6
0
 function deviceInfo()
 {
     $client = Client::get_instance();
     // Referral
     $client->referrer = Useragent::referrer();
     // Heavy detections will be cached in cookie
     $cookieStore = array('device', 'browser', 'browserVersion', 'os', 'country', 'city', 'lat', 'lon', 'timezone');
     $device_info_cookie = Cookie::get('device_info');
     if ($device_info_cookie && ($device_info_cookie = json_decode($device_info_cookie))) {
         foreach ($cookieStore as $key) {
             $client->{$key} = $device_info_cookie->{$key};
         }
     } else {
         // Device and browser
         // Use Mobile_Detect for better device recognition
         $client->device = Useragent::is_mobile() ? 'phone' : 'computer';
         $client->browser = Useragent::browser();
         $client->browserVersion = Useragent::version();
         $client->os = Useragent::platform();
         // Geolocation
         // Defaults to Kyiv
         $gb = new IPGeoBase();
         $geo = $gb->getRecord($client->ip);
         $client->country = empty($geo['cc']) ? 'UA' : $geo['cc'];
         $client->city = empty($geo['city']) ? 'Киев' : $geo['city'];
         $client->lat = empty($geo['lat']) ? 50.4501 : $geo['lat'];
         $client->lon = empty($geo['lon']) ? 30.5234 : $geo['lon'];
         $client->timezone = empty($geo['timezone']) ? Config::get('application.timezone', 'Europe/Kiev') : $geo['timezone'];
         $cookieStoreData = new \stdClass();
         foreach ($cookieStore as $key) {
             $cookieStoreData->{$key} = $client->{$key};
         }
         Cookie::make('device_info', json_encode($cookieStoreData), 60 * 60 * 4);
     }
 }
Example #7
0
<?php

require_once "ipgeobase.php";
$gb = new IPGeoBase();
$ip = $_SERVER['REMOTE_ADDR'];
$data = $gb->getRecord($ip);
print_r($data);
/*
array(7) {
  ["range"]=>
  string(27) "46.46.128.0 - 46.46.169.255"
  ["cc"]=>
  string(2) "RU"
  ["city"]=>
  string(6) "Москва"
  ["region"]=>
  string(6) "Москва"
  ["district"]=>
  string(29) "Центральный федеральный округ"
  ["lat"]=>
  string(9) "55.755787"
  ["lng"]=>
  string(9) "37.617634"
}
*/
$data = $gb->getRecord('192.168.0.1');
var_dump($data);
//bool(false)
Example #8
0
<?php

require_once "ipgeobase.php";
$gb = new IPGeoBase();
$data = $gb->getRecord('46.46.152.210');
var_dump($data);
/*
array(7) {
  ["range"]=>
  string(27) "46.46.128.0 - 46.46.169.255"
  ["cc"]=>
  string(2) "RU"
  ["city"]=>
  string(6) "Москва"
  ["region"]=>
  string(6) "Москва"
  ["district"]=>
  string(29) "Центральный федеральный округ"
  ["lat"]=>
  string(9) "55.755787"
  ["lng"]=>
  string(9) "37.617634"
}
*/
$data = $gb->getRecord('192.168.0.1');
var_dump($data);
//bool(false)
Example #9
0
if (isset($_SESSION["memberID"])) {
    require_once "includes/member.class.php";
    $member = new Member($_SESSION["memberID"]);
    if ($member->memberCityID > 0 && $member->memberCityID < 999) {
        $sql = "SELECT `cityName` FROM `cityList` WHERE `cityID` = '{$member->memberCityID}'";
        $cityName = $db->queryRow($sql);
        if (isset($cityName->cityName)) {
            $detected_city = $cityName->cityName;
            $detected_cityID = $member->memberCityID;
        }
    }
} else {
    $gb = new IPGeoBase();
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    $data = $gb->getRecord($ip);
    $detected_city = "Выберите город";
    if ($data["city"]) {
        $detected_city = iconv("windows-1251", "utf-8", $data["city"]);
    }
    $cityID = $api->getCityID($detected_city);
    $detected_cityID = false;
    if (isset($cityID->cityID) && $cityID->cityID > 0) {
        $detected_cityID = $cityID->cityID;
    }
}