Home  >  Article  >  Backend Development  >  Yii cookie operation method example

Yii cookie operation method example

WBOY
WBOYOriginal
2016-07-25 08:53:02915browse
  1. $cookie = new CHttpCookie('mycookie','this is my cookie');
  2. $cookie->expire = time()+60*60*24*30; //Limited to 30 days
  3. Yii::app()->request->cookies['mycookie']=$cookie;
Copy code

2, read cookies:

  1. $cookie = Yii::app()->request->getCookies();
  2. echo $cookie['mycookie']->value;
Copy code

3, Destroy cookies:

  1. $cookie = Yii::app()->request->getCookies();
  2. unset($cookie[$name]);
Copy code

The above is in the yii framework The most basic cookie operation method is well encapsulated and very simple to use.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn