PHPフレームワーク「Codeigniter」のcookieを設定する方法まとめ

1.cookieの設定方法1
setcookie(“user_id",$user_info['user_id’],86500);
setcookie(“username",$user_info['username’],86500);
setcookie(“password",$user_info['password’],86500);
//echo $_COOKIE['username’];

2.cookieの設定方法2
$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’];
//echo $_COOKIE['password’];

3.cookieの設定方法3
set_cookie(“username",$user_info['username’],60);
set_cookie(“password",$user_info['password’],60);
set_cookie(“user_id",$user_info['user_id’],60);
//echo get_cookie(“username");

4.コアコントローラクラス
<?php
class Demo_Controller extends CI_Controller{

public function __construct(){
parent::__construct();
$this->load->helper(“url");
$this->load->model(“user_model");
$this->cur_user=$this->user_model->is_login();
if($this->cur_user === false){
header(“location:".site_url(“index/login"));
}else{

$this->input->set_cookie(“username",$this->cur_user['username’],60);
$this->input->set_cookie(“password",$this->cur_user['password’],00);
$this->input->set_cookie(“user_id",$this->cur_user['user_id’],60);
}
}
}
?>

PHP

Posted by arkgame