<?php
class Session_demo extends CI_Controller {
	public function index(){}
	
	public function __construct(){
		parent::__construct();
		$this->load->library('session');
	}
	
	// 先存储session 
	// http://127.0.0.1:8000/CodeIgniter-3.0.0/session_demo/set_session
	// 在取出sesson(刷新演示一次性的数据)
	// http://127.0.0.1:8000/CodeIgniter-3.0.0/session_demo/show_session
	public function set_session() {
		//echo md5(uniqid());exit;
		
		$user = array('id'=>3,'name'=>'jack');
		
		// 相当于原生的:
		// session_start();
		// $_SESSION["user"] = $user;
		
		$user = $this->session->set_userdata ( 'user', $user );
		var_dump($user);//取出来NULL
		echo '<br>';
		
		//取session
		$user = $this->session->userdata('user');
		var_dump($user);
		
		//一次性的数据,只能读一次
		$this->session->set_flashdata('test','testdate-aaaaaaaaaaaa');
	}
	
	//http://127.0.0.1:8000/CodeIgniter-3.0.0/session_demo/show_session
	public function show_session(){
		//获取CI session中的数据
		$user = $this->session->userdata('user');
		var_dump($user);
		
		//只可以取一次,取完后就会被删除.
		$test=$this->session->flashdata('test');
		var_dump($test);
	}
	
	public function delete_session(){
		//删除单个session
		$result = $this->session->unset_userdata('user');
		var_dump($result);
// 		//删除多个session
// 		$array_items = array('user', 'test');
// 		$this->session->unset_userdata($array_items);
	}
}