PHPcookie的设置
setcookie('username',$data['username'],time()+3600*24*7);
YII2cookie的设置
$cookies = Yii::$app->response->cookies; $cookies->add(new \yii\web\Cookie([ 'name' => 'username', 'value' => $data['username'], 'expire'=>time()+3600*24*7, ]));
PHPcookie的读取
echo $_COOKIE['username'];
YII2cookie的读取
$cookies = Yii::$app->request->cookies;//注意此处是request echo $language = $cookies->get('username');//设置默认值
PHPcookie的检测
if(isset($_COOKIE["user"])){ }
YII2cookie的检测
$cookies = Yii::$app->request->cookies; if (isset($cookies['user'])){ }if ($cookies->has('user')){ }if (isset($cookies['user'])){ }
PHPcookie的删除
setcookie("user", "", time()-1);unset($_COOKIE['user']);
YII2cookie的删除
$cookies = Yii::$app->request->cookies; $cookies->remove('user');
其实说白了,框架的存储就是安全性高!
不好读出来的!