I am trying to install an additional cookie for the user, but the cookie is not installed, I checked it on another site under the same conditions, then all the rules are set and read. What could be the problem ? Even such a simple code does not 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>"; 

and in the array with cookies there are no cookies with the key I need, tell me how you can solve this problem?

and the strange thing is that even through <? setcookie('USER','asdas');?> <? setcookie('USER','asdas');?> do not put a cookie, the site has several aliases, as long as there are no thoughts what could be wrong ...

  • And tried to get it bitrix method - $ APPLICATION-> get_cookie ()? - Mihanik71
  • yes I tried, there is no result ( - Sergey Zaigraev
  • one
    Your worker code is Mihanik71
  • mihanik71.ru/novaya-stranitsa.php posted it. Everything Works - Mihanik71
  • Can any error in the development of the site affect it? Just yes, I also posted on other sites on Bitrix and all the rules work there .. - Sergey Zaigraev

2 answers 2

So the value of this cookie is obtained only on the second hit. On the current hit, only the command to install it is given. In fact, if you look at the browser, is it installed?

  • yes, after the second reboot, the cookie should get up, but this does not happen, that is, before updating, I comment on the line with the installation of cookies and there is nothing in the array. - Sergey Zaigraev
  • Then nothing is clear, as said above, the code is working. I work out - Dmitry Kozlov
  • Is there only this cookie in $ _COOKIE or is it empty at all? - Dmitry Kozlov
  • yes, not only the cookie I need - Sergey Zaigraev

Most likely the problem is that they worked on a local host with an address of the form http: // localhost: 6449 / . It is necessary to correct in the site settings - Domain name: leave blank, server URL (without http: //): localhost