要想在CodeIgniter框架使用Session,
首先:打开application/config文件夹下的config.php文件,找到:
$config['encryption_key'] ='';
设置encryption_key,例如改为:
$config['encryption_key'] ='ffasfas@$#364F32423J';
然后在要使用Session的地方加入:
$this->load->library('session');
//多个一起设置
$session=array('name'=>'andy','site'=>'q-blog');
$this->session->set_userdata($session);
//单个设置
$this->session->set_userdata('testname','abc');
获取Session:
echo$this->session->userdata('name');