dongyan1625 2016-06-02 06:48
浏览 33
已采纳

codeigniter url加密不起作用

<a href="<?php echo base_url().'daily_report/index/'.$this->encrypt->encode($this->session->userdata('employee_id')) ?>">

i have encrypted the above url using the codeigniter encrypt i set the encryption key in codeigniter config file

$config['encryption_key'] = 'gIoueTFDwGzbL2Bje9Bx5B0rlsD0gKDV';

and i called in the autoload

$autoload['libraries'] = array('session','form_validation','encrypt','encryption','database');

when the ulr(href) load into the url it look like this

http://localhost/hrms/daily_report/index/FVjGcz4qQztqAk0jaomJiAFBZ/vKVSBug1iGPQeKQCZ/K7+WUE4E/M9u1EjWh3uKTKeIhExjGKK1dJ2awL0+zQ==

but the url is not decoded, and i;m not getting the employee_id it shows empty.

public function index($employee_id) {
        $save_employee_id = $employee_id;
        // decoding the encrypted employee id
        $get_employee_id = $this->encrypt->decode($save_employee_id);
        echo $employee_id; // answer: FVjGcz4qQztqAk0jaomJiAFBZ
        echo "<br>";
        echo $get_employee_id; // is display the null
        echo "<br>";

        exit();
        // get the employee daily report
        $data['get_ind_report'] =           $this->daily_report_model->get_ind_report($get_employee_id);
        // daily report page
        $data['header'] = "Daily Report";
        $data['sub_header'] = "All";
        $data['main_content'] = "daily_report/list";
        $this->load->view('employeelayout/main',$data);
    }

complete url(3) is

FVjGcz4qQztqAk0jaomJiAFBZ/vKVSBug1iGPQeKQCZ/K7+WUE4E/M9u1EjWh3uKTKeIhExjGKK1dJ2awL0+zQ==

it shows only

FVjGcz4qQztqAk0jaomJiAFBZ

i tried to change in the

$config['permitted_uri_chars'] = 'a-zA-Z 0-9~%.:_\-@=+';

by / in the permitted uri chars but it throwing error So, i need to encryption the $id in the url using the codeigniter encrypt class and decrypt in the server side to get the actual $id, So that i fetch data from the DB. any help would be appreciated

  • 写回答

3条回答 默认 最新

  • douyinghuo8874 2016-06-02 07:03
    关注

    You have to extend encryption class and avoid the / to get it working. Place this class in your application/libraries folder. and name it as MY_Encrypt.php.

    class MY_Encrypt extends CI_Encrypt
    {
        /**
         * Encodes a string.
         * 
         * @param string $string The string to encrypt.
         * @param string $key[optional] The key to encrypt with.
         * @param bool $url_safe[optional] Specifies whether or not the
         *                returned string should be url-safe.
         * @return string
         */
        function encode($string, $key="", $url_safe=TRUE)
        {
            $ret = parent::encode($string, $key);
    
            if ($url_safe)
            {
                $ret = strtr(
                        $ret,
                        array(
                            '+' => '.',
                            '=' => '-',
                            '/' => '~'
                        )
                    );
            }
    
            return $ret;
        }
    
        /**
         * Decodes the given string.
         * 
         * @access public
         * @param string $string The encrypted string to decrypt.
         * @param string $key[optional] The key to use for decryption.
         * @return string
         */
        function decode($string, $key="")
        {
            $string = strtr(
                    $string,
                    array(
                        '.' => '+',
                        '-' => '=',
                        '~' => '/'
                    )
            );
    
            return parent::decode($string, $key);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?