Answer the question
In order to leave comments, you need to log in
Why cookies don't work (Yii2)?
There is domain1.com and domain2.com
from domain1.com we send a request on domain2.com Ajax to the page /ajax/cookie
$cookies = Yii::$app->request->cookies;
if (!$cookies->has($cookieName)) {
Yii::$app->response->cookies->add(new \yii\web\Cookie([
'name' => $cookieName,
'value' => 'test',
'expire' => time() + 3600 * 24 * 365
]));
} else {
$value = Yii::$app->response->cookies->get($cookieName);
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Tweaked your code a little.
$cookies = Yii::$app->request->cookies;
if (!$cookies->has($cookieName)) {
Yii::$app->response->cookies->add(new \yii\web\Cookie([
'name' => $cookieName,
'value' => 'test',
'expire' => time() + 3600 * 24 * 365
]));
} else {
$value = $cookies->get($cookieName);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question