R
R
run1822018-08-20 12:20:44
1C-Bitrix
run182, 2018-08-20 12:20:44

Why are cookies not being written?

require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
use Bitrix\Main\Application;
use Bitrix\Main\Web\Cookie;
    $application = Application::getInstance();
    $context = $application->getContext();

    $cookie = new Cookie("CARD_NUMBER", substr($_POST["phone"], 1), time() + 60*60*24*30*12*2);
    $cookie->setDomain($context->getServer()->getHttpHost());
    $cookie->setHttpOnly(false);

    $context->getResponse()->addCookie($cookie);
    $context->getResponse()->flush("");

I call this script via ajax jquery.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
run182, 2018-08-25
@run182

use Bitrix\Main\Application;
use Bitrix\Main\Web\Cookie;
$context = Application::getInstance()->getContext();
$cookie = new Cookie("CARD_NUMBER", $card, time() + 60*60*24*30*12*2);
$cookie->setDomain($context->getServer()->getHttpHost());
$cookie->setHttpOnly(false);
$cookie->setSecure(false);
$context->getResponse()->addCookie($cookie);
$context->getResponse()->flush("");

Added $cookie->setSecure(false); and it worked!

A
Alexey Emelyanov, 2018-08-20
@babarun

I call this script via ajax jquery.
- Are these cookies present in the response?
If protocol is not https then$cookie->setSecure(false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question