This example describes the method for CI manipulation cookies. Share to everyone for your reference, specific as follows:
CI operation Cookie has three kinds of methods, 2 of CI, which we mainly explain the last method of CI cookies, that is, the use of helpers with the class library, the operating methods are as follows:
To introduce a class library:
$this->load->helper (' Cookie ');
Set cookies
Set_cookie ("Cookie name", $cookie information, times expiration);
How to get
Get_cookie ("cookie name");
Because a lot of small pages need to set cookies, so I encapsulated a small method: the following
I like to operate in a parent class that inherits from a class, because the framework introduces a parent class, so some common information is defined as a method and placed in the parent class. Code in:
Generate cookies
Public Function Savecookie ($info, $time) {
$this->load->helper (' cookie ');
Set_cookie ("UserInfo", $info, $time);
Userinfo:cookie name. $info: The cookie to save. $time set a retention period, which is the expiration Time
}
Get cookies:
The Public Function GetCookie ($info) {
//$info is actually formed, when this method is invoked, the cookie name is entered when the call is called
$this-> Load->helper ("cookie");
Return Get_cookie ($info);
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design based on CodeIgniter framework.