I
I
Igor2020-06-22 17:13:03
1C-Bitrix
Igor, 2020-06-22 17:13:03

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;


This thing seems to be saving in cookies, but it is crossed out and deprecated, I understand that it does not save anywhere
. If it saves, how can I see what it stores?

And where it is better to write down the city if the visitor has changed it.

I see a solution to write the city in $_COOKIE, if the visitor changed the city, then update this cookie, maybe there is a better solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-07-01
@peretc001

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 question

Ask a Question

731 491 924 answers to any question