這篇文章主要介紹了php防止sql注入中過(guò)濾分頁(yè)參數(shù)的方法,實(shí)例展示了針對(duì)分頁(yè)參數(shù)的數(shù)值判斷問(wèn)題,是非常具有實(shí)用價(jià)值的技巧,需要的朋友可以參考下
本文實(shí)例講述了php防止sql注入中過(guò)濾分頁(yè)參數(shù)的方法。分享給大家供大家參考。具體分析如下:
就網(wǎng)絡(luò)安全而言,在網(wǎng)絡(luò)上不要相信任何輸入信息,對(duì)于任何輸入信息我們都必須進(jìn)行參數(shù)過(guò)濾。對(duì)此,我們先來(lái)看看下面的實(shí)例:
復(fù)制代碼代碼如下:
$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'] = '第一頁(yè)';
$config ['last_link'] = '最后一頁(yè)';
$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.'頁(yè)-留言本-防SQL注入測(cè)試';
}
else{
$data ['title'] = '留言本-防SQL注入測(cè)試';
}
$data ['liuyan'] = $this->ly->getLy ( $pernum, $currentnum );
其中:
復(fù)制代碼代碼如下:
$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;
這兩句判斷了參數(shù)是否為數(shù)字。防止非法字符輸入。
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。