Home > php教程 > php手册 > body text

CodeIgniter中使用cookie的三种方式详解

WBOY
Release: 2016-06-06 20:20:02
Original
1133 people have browsed it

这篇文章主要介绍了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");

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!