我曾经在我的网址ex中加密我的数据的ID。 mywebsite.com/product/detail/encryptedid然后,如果我去那个链接,它将显示该特定产品的所有信息。但是当我试图改变一些随机字符串ex之前的encryptedid。 mywebsite.com/product/detail/asd123它会显示错误"试图获取非对象的属性"我很好奇如何以这样的方式阻止它,比如他们会将加密的URL更改为一些随机字符串,它可以重定向到原来的mywebsite.com/product/detail/encryptedid,它仍将显示该特定的信息产品或转到404页。
以清楚的例子看下面的图片。
带加密的图片
输入随机字符串的图片
编辑:
我的控制器
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');
}
查看
<a href="<?= base_url() .'products/details/' . secret_url('encrypt',$featured_row->product_id) ?>"></a>
提前谢谢。
答案 0 :(得分:1)
就像没有产品一样:
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 = '');
}
}