简体   繁体   English

Codeigniter网址重定向

[英]Codeigniter url redirect

I used to encrypt the id of my data in my url ex. 我曾经在url前加密我的数据ID。 mywebsite.com/product/detail/encryptedid then if i would go to that link it will show all the info of that specific product. mywebsite.com/product/detail/encryptedid,然后如果我转到该链接,它将显示该特定产品的所有信息。 but when i tried to change the encryptedid such as some random string ex. 但是当我尝试更改诸如某些随机字符串ex之类的cryptonid时。 mywebsite.com/product/detail/asd123 it will show the error "Trying to get property of non-object" I'm curious how to prevent it in such a way like if they will change the encrypted url to some random strings it can redirect to the original mywebsite.com/product/detail/encryptedid which will show still the info of that specific product or go to 404 page. mywebsite.com/product/detail/asd123它将显示错误“试图获取非对象的属性”我很好奇如何防止这种错误,例如如果他们将加密的url更改为一些随机字符串,可以重定向到原始的mywebsite.com/product/detail/encryptedid,该页面仍会显示该特定产品的信息,或转到404页。

for clear example look at the image below. 要获得清晰的示例,请看下面的图片。

Image with encryption 加密图像

带有加密ID

Image with inputted random string 输入了随机字符串的图像

没有加密ID

EDITED: 编辑:

My Controller 我的控制器

public function details($id){

    $decrypt = secret_url('decrypt',$id);

    $prod_row = $this->ProductModel->getonerow($decrypt);
    $data['product_detail'] = $prod_row;

    $data['title'] = "Ayos Computer | Product Details";
    $data['category'] = $this->ProductModel->get_category();
    $data['products'] = $this->ProductModel->get_product();

    $this->load->view('include/header',$data);
    $this->load->view('include/nav');
    $this->load->view('products/ProductDetail', $data);
    $this->load->view('include/footer');
}

VIEW 视图

 <a href="<?= base_url() .'products/details/' . secret_url('encrypt',$featured_row->product_id) ?>"></a>

thank you in advance. 先感谢您。

As same way as if there was no product: 就像没有产品一样:

public function details($id)
{

    $decrypt = secret_url('decrypt',$id);

    $prod_row = $this->ProductModel->getonerow($decrypt);

    if (null !== $prod_row) {
        $data['product_detail'] = $prod_row;

        $data['title'] = "Ayos Computer | Product Details";
        $data['category'] = $this->ProductModel->get_category();
        $data['products'] = $this->ProductModel->get_product();

        $this->load->view('include/header',$data);
        $this->load->view('include/nav');
        $this->load->view('products/ProductDetail', $data);
        $this->load->view('include/footer');
    } else {
        // CI default 404 view if left blank value
        show_404($custom_page = '');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM