Encrypt the data and write it into a cookie.
- $cookie _data = $this, Encrypt ("Nowamagic", $data);
$cookie = Array (
- ' Name ' = ' $data ',
- ' Value ' = $cookie _data,
- ' Expire ' = $user _expire,
- ' Domain ' = ',
- ' Path ' = '/',
- ' prefix ' and ' = '
- );
- $this->input->set_cookie ($cookie);
Encryption
- Public function Encrypt ($key, $plain _text) {
- $plain _text = Trim ($plain _text);
- $IV = substr (MD5 ($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
- $c _t = MCRYPT_CFB (mcrypt_cast_256, $key, $plain _text, Mcrypt_encrypt, $IV);
- Return Trim (Chop (Base64_encode ($c _t));
- }//edit bbs.it-home.org 2013/6/7
Decrypt
- if (Isset ($_cookie[' data '))
- {
- Assign a value to a session with a cookie
- $_session[' data ' = Decrypt ("Nowamagic", $_cookie[' data ');
- }
Resolving functions
- function Decrypt ($key, $c _t) {
- $c _t = Trim (Chop (Base64_decode ($c _t));
- $IV = substr (MD5 ($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
- $p _t = MCRYPT_CFB (mcrypt_cast_256, $key, $c _t, Mcrypt_decrypt, $IV);
- Return Trim (Chop ($p _t));
- }
- ?>
Copy Code |