Home >Backend Development >PHP Tutorial >Introduction to yii operating cookie examples, yiicookie examples_PHP tutorial

Introduction to yii operating cookie examples, yiicookie examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:23:191121browse

Introduction to yii cookie operation examples, yiicookie examples

Yii’s common operations on cookies include the following:

1. Set cookies:

$cookie = new CHttpCookie('mycookie','this is my cookie'); 
$cookie->expire = time()+60*60*24*30; //有限期30天 
Yii::app()->request->cookies['mycookie']=$cookie;

2. Read cookie:

$cookie = Yii::app()->request->getCookies(); 
echo $cookie['mycookie']->value;

3. Destroy cookies:

$cookie = Yii::app()->request->getCookies(); 
unset($cookie[$name]);

httpclient 411 cookie operation example

blog.163.com/...56185/

JS simple example of reading COOKIES

/**Storage Cookies: Two parameters, one is the name of the cookie, the other is the value*/
function SetCookie(name,value){
var Days = 30; //This cookie will be Save for 30 days
var exp = new Date();//new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000) ;
document.cookie = name + "="+ escape (value) + ";expires="+exp.toGMTString();
}
/**Get cookies function*/
function getCookie(name){
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]); return null;
}
/**Delete cookie*/
function delCookie(name){
var exp = new Date( );
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+ ";expires="+exp.toGMTString();
}

You can operate wherever you want

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/840745.htmlTechArticleIntroduction to yii cookie operation examples, yiicookie examples yii common operations on cookies include the following: 1. Settings cookie: $cookie = new CHttpCookie('mycookie','this is my cookie'); $coo...
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