PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
设置Cookies
$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']);
转载请注明:谷谷点程序 » yii2使用cookie的方法