Answer the question
In order to leave comments, you need to log in
Why is Sypex Geo not working?
Please help. Sypex Geo does not determine the location. In the php console of Bitrix I execute the following code:
$ip = $_SERVER["REMOTE_ADDR"];
if(!empty($_SERVER["HTTP_X_REAL_IP"])){
$ip = $_SERVER["HTTP_X_REAL_IP"];
}
$obBitrixGeoIPResult = \Bitrix\Main\Service\GeoIp\Manager::getDataResult($ip, 'ru');
if($obBitrixGeoIPResult !== \Bitrix\Main\Service\GeoIp\Manager::INFO_NOT_AVAILABLE){
if($obResult = $obBitrixGeoIPResult->getGeoData()){
$_SESSION['GEOIP'] = get_object_vars($obResult);
$city = isset($_SESSION['GEOIP']['cityName']) && $_SESSION['GEOIP']['cityName'] ? $_SESSION['GEOIP']['cityName'] : '';
}
}
print_r($_SESSION['GEOIP']);
Array
(
[ip] => 62.33.36.6
[lang] => ru
[countryName] =>
[regionName] =>
[subRegionName] =>
[cityName] =>
[countryCode] =>
[regionCode] =>
[zipCode] =>
[latitude] =>
[longitude] =>
[timezone] =>
[asn] =>
[ispName] =>
[organizationName] =>
[handlerClass] => Bitrix\Main\Service\GeoIp\SypexGeo
)
Answer the question
In order to leave comments, you need to log in
The method \Bitrix\Main\Service\GeoIp\Manager::getDataResult
is a wrapper over the geolocation handlers, which are located here Settings > Product settings > Geolocation
On this page you can see the list of handlers. The above method selects a handler according to sorting and tries to make a request through its API. If a result was received, then it returns it as an object \Bitrix\Main\Service\GeoIp\Result
, otherwise the request goes through the next handler.
For Sypex Geo, the handler is a class \Bitrix\Main\Service\GeoIp\SypexGeo
located here /bitrix/modules/main/lib/service/geoip/sypexgeo.php
I tried to directly make a request through the Sypex Geo handler using the IP from your example:
$ob = new \Bitrix\Main\Service\GeoIp\SypexGeo();
$res = $ob->getDataResult("62.33.36.6");
print_r($res);
Bitrix\Main\Service\GeoIp\Result Object
(
[geoData:protected] => Bitrix\Main\Service\GeoIp\Data Object
(
[ip] => 62.33.36.6
[lang] => en
[countryName] => Russia
[regionName] => Tambovskaya Oblast'
[subRegionName] =>
[cityName] => Michurinsk
[countryCode] => RU
[regionCode] => RU-TAM
[zipCode] =>
[latitude] => 52.8978
[longitude] => 40.4907
[timezone] => Europe/Moscow
[asn] =>
[ispName] =>
[organizationName] =>
[handlerClass] =>
)
[isSuccess:protected] => 1
[errors:protected] => Bitrix\Main\ErrorCollection Object
(
[values:protected] => Array
(
)
)
[data:protected] => Array
(
)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question