PHP code example of jsnlib / codeigniter_encryption
1. Go to this page and download the library: Download jsnlib/codeigniter_encryption library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jsnlib / codeigniter_encryption example snippets
class Welcome extends CI_Controller {
public function index()
{
// 1. 使用 encryption 類別
$this->load->library('encryption');
// 2. 初始化並在建構子置入 CI 原生的 encryption 物件
$this->jsnlib_ecp = new \Jsnlib\Codeigniter\Encryption($this->encryption);
// 3. 產生加密字串
$token = $this->jsnlib_ecp->encrypt(
[
'name' => 'Jason',
'age' => 18,
'expiry' => '2019-01-01 10:00:00' //若不指定過期時間,將自動添加預設值
]);
// 4. 解密字串
$ary = $this->jsnlib_ecp->decrypt($token);
}
}