Answer the question
In order to leave comments, you need to log in
Where to store the Bitrix visitor's city?
Good afternoon
Tell me how best to store and change the visitor
's city The city is determined by the standard Bitrix method:
use \Bitrix\Main\Service\GeoIp;
use \Bitrix\Main\Service\GeoIp\SypexGeo;
GeoIp\Manager::useCookieToStoreInfo(true);
$ip = GeoIp\Manager::getRealIp();
$city = GeoIp\Manager::getCityName($ip, 'ru');
echo $city;
Answer the question
In order to leave comments, you need to log in
useCookieToStoreInfo deprecated, inside the function just return
This will be enough
GeoIp\Manager::getRealIp() is not needed, this method will be called if the first parameter in getCityName is an empty string.
All data is written to session
$_SESSION['BX_GEO_IP']
$city = GeoIp\Manager::getCityName('', 'ru');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question