dsjq62428 2017-02-07 02:03
浏览 50

CodeIgniter 3.1.3发送加密的URL变量偶尔不起作用

I am trying to pass an encrypted user_ID variable through url using the new CI encryption library, passing the variable into the controller and into the model to run a query based on the passed variable value. The problem is sometimes it is working and sometimes it is not. I set my encryption key by the instruction given in the user guide and i have load the library in the autoload:

$key = bin2hex($this->encryption->create_key(16));

and setting the key into config.php:

$config['encryption_key'] = bin2hex('some_bin2hex_numbers_and_letters');

View (getting the variable to be pass):

<div class="col-sm-8">
    <?php foreach ($user_list as $row) {
        $ID = $row['user_ID'];
        $UID = $this->encryption->encrypt($ID);
        $username = $row['user_Username'];
        $firstname = $row['user_FirstName'];
        $lastname = $row['user_LastName']; 
    ?>

    <a href="<?php echo base_url()?>Admin/User?uid=<?php echo $UID;?>">
        <h2 style="font-family:'Comic Sans MS', cursive;\"> <?php echo $username." (".$firstname." ".$lastname.") </h2> <br />" ?>
    </a>

    <?php } ?>
</div>

Controller:

public function User() {
    $ID  = $this->input->get('uid');
    $UID = $this->encryption->decrypt($ID);
    $data['user'] = $this->Admin_model->getUserData($UID);
    $this->load->view('pages/admin/admin_header');  
    $this->load->view('pages/admin/admin_user_data', $data);    
    $this->load->view('templates/footer2'); 
}

model (to get the passed variable and return a row):

public function getUserData($UID) {
    $query = $this->db->query("SELECT * FROM `tbl_user` WHERE `tbl_user`.`user_ID`='$data'");
    $row = $query->row();
    return $row;
}

view admin_user_data (the view to display the result of passed variable):

<h1>
    <?php 
    echo "User ID: ".$user->user_ID."<br />";
    echo "Username: ".$user->user_Username."<br />";
    echo "First Name: ".$user->user_FirstName."<br />";
    echo "Last Name: ".$user->user_LastName."<br />";
    ?>
</h1>
  • 写回答

1条回答 默认 最新

  • doueta6642 2017-02-07 04:52
    关注

    Actually this method work for me.

    For encryption

    $this->load->library('encryption'); 
    
    $this->encryption->initialize(
    array(
           'cipher' => 'aes-256',
           'mode' => 'ctr',
           'key' => '4lWC8cegO92vhTRbiRy21sh90TwFz6DR' // A random key generated by visiting http://randomkeygen.com/
         )
    );   
    
    $enc_id = $this->encryption->encrypt($id);
    

    For decryption

        $this->load->library('encryption'); 
    
        $this->encryption->initialize(
        array(
                'cipher' => 'aes-256',
                'mode' => 'ctr',
                'key' => '4lWC8cegO92vhTRbiRy21sh90TwFz6DR' // Same key you used for encryption
            )
        );  
    
        $dec_id = $this->encryption->decrypt($enc_id);
    

    The above approach work for me every time. Please comment below if you encountered any problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端