Method Analysis of CI manipulation cookies (based on helper class library) _php instance

Source: Internet
Author: User
Tags codeigniter

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.

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.