1.添加修改cookies

$cookie=array("name"=>"user","value"=>"demo1","expire"=>24*3600,‘httpOnly' => true,);
Yii::$app->response->cookies->add(new Cookie($cookie));

2.删除cookies

Yii::$app->response->cookies->remove("user");

3.获取cookies

Yii::$app->response->cookies->get('user');
Yii::$app->request->cookies->getValue('user');

4.判断cookies

if($cookies->has('language'))
if(isset($cookies['language']))

5.其他

$lifetime = $this->rememberMe ? 24*3600 : 0;
session_set_cookie_params($lifetime);
ip2long(Yii::$app->request->userIP)

上一篇:Yii2学习笔记二:表单提交CSRF验证

下一篇:Yii2学习笔记四:视图之数据块