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 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭