Home >Backend Development >PHP Tutorial >Analysis of CI cookie operation methods (based on helper class library), cookiehelper_PHP tutorial

Analysis of CI cookie operation methods (based on helper class library), cookiehelper_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:55:08966browse

Analysis of the method of CI operating cookies (based on the helper class library), cookiehelper

This article describes the method of CI operating cookies. Share it with everyone for your reference, the details are as follows:

There are three methods for CI to operate cookies. Among them, Ci comes with 2. Among them, we mainly explain the last method of ci cookie, which is to use the helpers’ built-in class library. The operation method is as follows:

Introduce class library:

$this->load->helper('cookie');

Set cookies

set_cookie("cookie名称",$cookie信息,times过期时间);

How to get it

get_cookie("cookie名称");

Since many small pages need to set cookies, I have encapsulated a small method: as follows
I like to operate in the parent class that the class inherits, because the framework introduces a parent class, so I will define some public information as methods and put them in the parent class. Enter the code below:

Generate cookie

public function saveCookie($info,$time){
  $this->load->helper('cookie');
  set_cookie("userInfo",$info,$time);
  //userInfo:cookie名称。$info:要保存的cookie 。$time 设置保存期,即过期时间
}

Get cookie:

public function getCookie($info){
   //$info实际就是形成,调用这个方法的时候,需要获取哪个cookie名称就在调用的时候输入cookie名称
   $this->load->helper("cookie");
   return get_cookie($info);
}

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

Articles you may be interested in:

  • Analysis of the operation method of cookies in the CI framework
  • How to delete and set cookies in CodeIgniter
  • Use of cookies in CodeIgniter Detailed explanation of the three methods
  • CodeIgniter configuration SESSION usage example analysis
  • Analysis of how to use the framework's session in the PHP framework codeigniter
  • Detailed explanation of the CodeIgniter auxiliary function helper
  • CodeIgniter-assisted third-party library third_party usage analysis
  • Codeigniter integrated Tank Auth permission class library detailed explanation
  • Using CodeIgniter class library to upload images

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117092.htmlTechArticleAnalysis of the method of CI operating cookies (based on the helper class library), cookiehelper This article describes the method of CI operating cookies. Share it with everyone for your reference, the details are as follows: There are three CI operation cookies...
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