Yii operation cookie instance introduction, yiicookie instance _ PHP Tutorial

Source: Internet
Author: User
Tags set cookie
Yii operation cookie instance introduction, yiicookie instance. Yii operation cookie instance introduction, yiicookie instance yii has the following common cookie operations: 1. set cookie: $ cookienewCHttpCookie (mycookie, thisismycookie); $ coo yii operation cookie instance introduction, yiicookie instance

Yii has the following common cookie operations:

1. set cookie:

$ Cookie = new CHttpCookie ('mycooker', 'This is my cooker'); $ cookie-> expire = time () + 60*60*24*30; // There is a time limit of 30 days. Yii: app ()-> request-> cookies ['mycookier'] = $ cookie;

2. read cookie:

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

3. destroy cookie:

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


Httpclient 411 cookie operation instance

Blog.163.com/..56185/

Simple example of JS reading COOKIES

/** Store Cookies: two parameters: one is the cookie name and the other is the value */
Function SetCookie (name, value ){
Var Days = 30; // This cookie will be saved for 30 Days
Var exp = new Date (); // new Date ("December 31,999 8 ");
Exp. setTime (exp. getTime () + Days x 24x60*60*1000 );
Document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();
}
/** Use cookies */
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 anywhere you want.

Policyii has the following common cookie operations: 1. set cookie: $ cookie = new CHttpCookie ('mycookier', 'This is my cookier'); $ coo...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.