分页参数怎么防止SQL注入

时间:2022-12-06 01:26

分页参数怎么防止SQL注入

分页参数防止SQL注入的方法:

对任何输入信息都必须进行参数过滤,php实例:

$this->load->library ( 'pagination' );

$config ['base_url'] = site_url () . '/guest/show';

$config ['total_rows'] = $c;

$config ['per_page'] = $pernum = 15;

$config ['uri_segment'] = 3;

$config ['use_page_numbers'] = TRUE;

$config ['first_link'] = '第一页';

$config ['last_link'] = '最后一页';

$config ['num_links'] = 5;

$this->pagination->initialize ( $config );

if (! $this->uri->segment ( 3 )) {

$currentnum = 0;

} else {

$currentnum = is_numeric($this->uri->segment ( 3 ))?(intval($this->uri->segment ( 3 ) - 1)) * $pernum:0;

}

$current_page=is_numeric($this->uri->segment ( 3 ))?intval($this->uri->segment ( 3 )):1;

if($current_page){

$data ['title'] = '第'.$current_page.'页-留言本-防SQL注入测试';

}

else{

$data ['title'] = '留言本-防SQL注入测试';

}

$data ['liuyan'] = $this->ly->getLy ( $pernum, $currentnum );

其中以下这两句判断了参数是否为数字,防止非法字符输入。

$current_page=is_numeric($this->uri->segment ( 3 ))?intval($this->uri->segment ( 3 )):1;

$currentnum = is_numeric($this->uri->segment ( 3 ))?(intval($this->uri->segment ( 3 ) - 1)) * $pernum;

标签:
随便看看
本类推荐
本类排行
热门标签

我国国家通讯社行不行啊细狗新年贺词祝福语2023年祝福语新年新年贺词新年贺词祝福语居家抗病毒小药箱除夕高速免费吗2022年除夕高速免费吗春联春联句子大全春联句子大全七字年夜饭十二道菜年夜饭十二道菜单年夜饭吃什么年夜饭吃什么菜吃年夜饭的寓意年夜饭黑芝麻菊花茶晒菊花茶腌腊肉送妈妈生日礼物汉白玉送闺蜜水钻送女人礼物爸爸生日送礼物送老公