search
Homephp教程php手册CodeIgniter中使用cookie的三种方式详解

这篇文章主要介绍了CodeIgniter中使用cookie的三种方式,非常简洁实用,需要的朋友可以参考下

cookie在php程序设计中应用十分广泛,本文所述CodeIgniter中使用cookie主要有以下三种方式,读者可以根据自身项目需求酌情采用。

第一种方式:采用php原生态的方法设置的cookie的值

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

第二种方式:通过CI框架的input类库设置cookie的值

$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");//适用于控制器 //echo$this->input->cookie("username");//适用于控制器 //echo$_COOKIE['username'];//在模型类中可以通过这种方式获取cookie值 //echo$_COOKIE['password'];//在模型类中可以通过这种方式获取cookie值

第三种方式:通过CI框架的cookie_helper.php辅助函数库设置cookie的值

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");

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools