错误:致命错误:调用未定义的函数ecrypt()
代码一切正常,没有锚点中的ecrypt函数调用。我希望通过代码注入来保护它。为什么我得到上述错误?
视图:
<?php
echo anchor("resetPasswordController/delete_news/".ecrypt($content1['id']),
'<i class="fa fa-trash-o fa-fw"></i>Delete','id="actions"', array
('onClick' => "return confirm('Are you sure you want to delete?')"));?>
控制器:
function delete_news() {
$this->load->library('encrypt');
$this->load->model('users_model');
//var_dump($product_id);die();
$ls_id= $this->decrypt($this->uri->segment(3));
$result = $this->users_model->get_id($ls_id);
$this->users_model->delete($ls_id);
$this->db->trans_complete();
$message2 = "News has been deleted successfully";
echo "<script type='text/javascript'>alert('$message2'); </script>";
$this->manage_news();
}
// Encryption function starts
function ecrypt($str)
{
$result ="";
$key = "snowtogsbydigitechsoftwaresolutionsabcxyzdfvdfd";
for($i=0; $i<strlen($str); $i++)
{
$char = substr($str, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
// Encryption function end
// This code use for id decrypt
function decrypt($str)
{
$str = base64_decode($str);
$result = '';
$key = "snowtogsbydigitechsoftwaresolutionsabcxyzdfvdfd";
for($i=0;$i<strlen($str); $i++)
{
$char = substr($str, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
// decryption function end
模型:
function delete($id){
$this->db->where('id', $id);
$this->db->delete('news');
}
function get_id($id){
$this->db->where('id',$id);
$query = $this->db->get('news');
return $query->result_array();
}
答案 0 :(得分:0)
在您的观点中:
<?php
$CI = & get_instance();
echo anchor("resetPasswordController/delete_news/".$CI->ecrypt($content1['id']),
'<i class="fa fa-trash-o fa-fw"></i>Delete','id="actions"', array
('onClick' => "return confirm('Are you sure you want to delete?')"));?>
更新解决方案 Base64返回一个最后有=的字符串,这可能会导致问题所以你可以替换它
function ecrypt($str)
{
$result ="";
$key = "snowtogsbydigitechsoftwaresolutionsabcxyzdfvdfd";
for($i=0; $i<strlen($str); $i++)
{
$char = substr($str, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
$data = base64_encode($result);
$data = str_replace(array('='),array('.'),$data);
return $data
}
同样替换&#39;。&#39; with = in decrypt function