Z
Z
zahar_922020-06-28 11:42:41
1C-Bitrix
zahar_92, 2020-06-28 11:42:41

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']);

At the output I get:
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
)

What is the problem? In the settings, Sypex Geo is installed and active.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2020-06-29
@zahar_92

The method \Bitrix\Main\Service\GeoIp\Manager::getDataResultis 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\SypexGeolocated 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);

Received the correct data set in response
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
        (
        )

)

You may have reached your request limit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question