手机
当前位置:查字典教程网 >编程开发 >php教程 >CodeIgniter中使用cookie的三种方式详解
CodeIgniter中使用cookie的三种方式详解
摘要:cookie在php程序设计中应用十分广泛,本文所述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");

【CodeIgniter中使用cookie的三种方式详解】相关文章:

PHP与MySQL交互使用详解

php使用cookie实现记住用户名和密码实现代码

在php中使用sockets:从新闻组中获取文章

php使用curl打开https网站的方法

如何在PHP中使用Oracle数据库(4)

Content-type 的说明

PHP中4种常用的抓取网络数据方法

如何在PHP中使用Oracle数据库(2)

PHP使用flock实现文件加锁的方法

Session的工作方式

精品推荐
分类导航