
yii2怎样把数据添加到cookie中
1个回答
展开全部
$cookies = Yii::$app->response->cookies;
// add a new cookie to the response to be sent
$cookies->add(new \yii\web\Cookie([
'name' => 'username',
'value' => 'yiiuser',
]));
获取 Cookies
$cookies = Yii::$app->request->cookies;
// get the cookie value
$username = $cookies->getValue('username');
//return default value if the cookie is not available
$username = $cookies->getValue('username', 'default');
// Check the availability of the cookie
if ($cookies->has('username'))
echo $cookies->getValue('username');
删除 Cookies
$cookies = Yii::$app->response->cookies;
$cookies->remove('username');
unset($cookies['username']);
// add a new cookie to the response to be sent
$cookies->add(new \yii\web\Cookie([
'name' => 'username',
'value' => 'yiiuser',
]));
获取 Cookies
$cookies = Yii::$app->request->cookies;
// get the cookie value
$username = $cookies->getValue('username');
//return default value if the cookie is not available
$username = $cookies->getValue('username', 'default');
// Check the availability of the cookie
if ($cookies->has('username'))
echo $cookies->getValue('username');
删除 Cookies
$cookies = Yii::$app->response->cookies;
$cookies->remove('username');
unset($cookies['username']);

2023-12-06 广告
网易云信提供一站式的 1 对 1 UIKit 组件库,可以更快地搭建 1 对 1 社交平台,能够快速实现音视频呼叫、音视频通话、1对1消息发送、美颜和礼物功能,直接可以复用我们的组件源码就可以了。优势:1、全套1对1 UI组件,接入更快;2...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询