我希望使用 Codeigniter 在 Url 中隐藏和显示唯一 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);
}