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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退