Answer the question
In order to leave comments, you need to log in
COOKIES. Why don't the $APPLICATION->set_cookie() and $APPLICATION->get_cookie() methods work?
I'm trying to set an additional cookie for the user, but the cookie is not set, I checked it on another site under the same conditions, then all the rules are set and read. What could be the problem ? Even this simple code doesn't work.
<?require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
$APPLICATION->set_cookie("USER_CITY","city");
echo "<pre>";
print_r($_COOKIE);
echo "</pre>";
<? setcookie('USER','asdas');?>
not to set a cookie, the site has several aliases, while there’s not even a thought what could be the matter ...
Answer the question
In order to leave comments, you need to log in
Cookies will only become visible after reloading the page for which they should be visible. To check if the cookies have been set correctly, check them on the next page load before they expire. The expiration date of the cookie is set in the expire parameter. It is convenient to check the existence of a cookie by simply calling print_r($_COOKIE);.php.net/manual/en/function.setcookie.php
replacement
require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_after.php');
to
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
helped. By the way, cookies in Bitrix should be written like this
$APPLICATION->set_cookie("favorites",serialize($arElements), time()+60*60*24*30*12*2, "/");
$APPLICATION->get_cookie('favorites')
is still available like this
$_COOKIE["BITRIX_SM_favorites"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question