Three methods for using cookies in CodeIgniter

Source: Internet
Author: User
This article mainly introduces three methods of using cookies in CodeIgniter, which are simple and practical. if you need them, refer to the CI framework.

Cookie is widely used in php programming. the following three methods are used in CodeIgniter, which can be used by readers according to their project requirements.

Method 1: use the original php method to set the cookie value

setcookie("user_id",$user_info['user_id'],86500);setcookie("username",$user_info['username'],86500);setcookie("password",$user_info['password'],86500);//echo$_COOKIE['username'];

Method 2: Set the cookie value through the input class library of the CI framework

$ This-> input-> set_cookie ("username", $ user_info ['username'], 60); $ this-> input-> set_cookie ("password ", $ user_info ['password'], 60); $ this-> input-> set_cookie ("user_id", $ user_info ['User _ id'], 60 ); // echo $ this-> input-> cookie ("password"); // applicable to controller // echo $ this-> input-> cookie ("username "); // applicable to controller // echo $ _ COOKIE ['username']; // you can obtain the cookie value in the model class in this way // echo $ _ COOKIE ['password']; // you can obtain the cookie value in the model class in this way.

Method 3: Use the cookie_helper.php helper function library in the CI framework to set the cookie value.

set_cookie("username",$user_info['username'],60);set_cookie("password",$user_info['password'],60);set_cookie("user_id",$user_info['user_id'],60);//echoget_cookie("username");

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.