cookie codeigniter 3.0.x上的加密

时间:2015-08-30 11:15:18

标签: codeigniter cookies encryption

这是我第一次使用加密库。我已阅读文档,并对字符串进行了一些加密。我想问一下这是一件有效的事情。

我的代码:

public function store_cookie($email){
    if($this->input->post('remember_me') == 'remember'){
        //try email later
        $cookie = array(
                'name'   => 'remember' ,
                'value'  => $email,
                'expire' => '86500',
                'prefix' => '',
                'secure' => FALSE
                );
        $this->input->set_cookie($this->encryption->encrypt($cookie));
    }
}

1 个答案:

答案 0 :(得分:1)

这不是存储加密Cookie的正确方法,加密值(如有必要)而非整个Cookie,请查看以下代码

public function store_cookie($email) {

    if($this->input->post('remember_me') == 'remember'){
        //try email later
        $cookie = array(
            'name'   => 'remember' ,
            'value'  => $this->encryption->encrypt($email),
            'expire' => '86500',
            'prefix' => '',
            'secure' => FALSE
        );
        $this->input->set_cookie($cookie);
    }
}