簡體   English   中英

我想使用Codeigniter隱藏該ID並在網址中顯示唯一ID?

[英]I want that id hide and show unique Id in Url using Codeigniter?

<a href="<?php echo base_url();?>index.php/registration/invoice/<?php echo ($rows['id']);?>">

function invoice()
{
    $paymentid=$this->uri->segment('3');$record=$this->Registration_model->get_data($paymentid);
}

使用base64_encode創建加密的ID

<a href="<?php echo base_url();?>index.php/registration/invoice/<?php echo base64_encode($rows['id']);?>">

function invoice()
{
    $paymentid=base64_decode($this->uri->segment('3'));
    $record=$this->Registration_model->get_data($paymentid);
}

使用base64_encode可以輕松解密。

請將這兩個函數添加到您的助手中以對ID進行編碼以解碼:

function encode_url($string)
{

        $CI =& get_instance();
        $CI->load->library('encryption');
        $ret = $CI->encryption->encrypt($string);
        return str_replace(array('+', '/', '='), array('-', '_', '~'),$ret);

}

function decode_url($string)
{
        $CI =& get_instance();
        $CI->load->library('encryption');
        $ret = str_replace(array('-', '_', '~'),array('+', '/', '='),$string);
        return $CI->encryption->decrypt($ret);
}

所以你會編碼

<a href="<?php echo base_url();?>index.php/registration/invoice/<?php echo encode_url($rows['id']);?>">

function invoice()
{
    $paymentid = decode_url($this->uri->segment('3'));

    $record = $this->Registration_model->get_data($paymentid);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM