


Analysis of CI cookie operation methods (based on helper class library), cookiehelper_PHP tutorial
Jul 12, 2016 am 08:55 AMAnalysis 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 設(shè)置保存期,即過期時間 }
Get cookie:
public function getCookie($info){ //$info實際就是形成,調(diào)用這個方法的時候,需要獲取哪個cookie名稱就在調(diào)用的時候輸入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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

The working principle of cookies involves the server sending cookies, the browser storing cookies, and the browser processing and storing cookies. Detailed introduction: 1. The server sends a cookie, and the server sends an HTTP response header containing the cookie to the browser. This cookie contains some information, such as the user's identity authentication, preferences, or shopping cart contents. After the browser receives this cookie, it will be stored on the user's computer; 2. The browser stores cookies, etc.

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

The dangers of cookie leakage include theft of personal identity information, tracking of personal online behavior, and account theft. Detailed introduction: 1. Personal identity information is stolen, such as name, email address, phone number, etc. This information may be used by criminals to carry out identity theft, fraud and other illegal activities; 2. Personal online behavior is tracked and analyzed through cookies With the data in the account, criminals can learn about the user's browsing history, shopping preferences, hobbies, etc.; 3. The account is stolen, bypassing login verification, directly accessing the user's account, etc.

Solutions for document.cookie not being obtained: 1. Browser privacy settings; 2. Same-origin policy; 3. HTTPOnly Cookie; 4. JavaScript code error; 5. Cookie does not exist or expires; 6. Cross-domain issues; 7. Viewer mode; 8. Server problems; 9. JavaScript execution timing; 10. Check console log, etc.

The effects of clearing cookies include resetting personalization settings and preferences, affecting ad experience, and destroying login status and password remembering functions. Detailed introduction: 1. Reset personalized settings and preferences. If cookies are cleared, the shopping cart will be reset to empty and products need to be re-added. Clearing cookies will also cause the login status on social media platforms to be lost, requiring re-adding. Enter your username and password; 2. It affects the advertising experience. If cookies are cleared, the website will not be able to understand our interests and preferences, and will display irrelevant ads, etc.

In our daily use of computers and the Internet, we are often exposed to cookies. A cookie is a small text file that saves records of our visits to the website, preferences and other information. This information may be used by the website to better serve us. But sometimes, we need to find cookie information to find the content we want. So how do we find cookies in the browser? First, we need to understand where the cookie exists. in browser
