首页 > 开发 > PHP > 正文

php防止sql注入之过滤分页参数

2024-05-04 21:58:46
字体:
来源:转载
供稿:网友

我们会听过这一种句话,在网络上不要相信任何输入信息,我们都必须进行参数过滤,下面我就来介绍过滤分页参数吧,有需要的朋友可参考,实例代码如下:

  1. $this->load->library ( 'pagination' ); 
  2. $config ['base_url'] = site_url () . '/guest/show'
  3. $config ['total_rows'] = $c
  4. $config ['per_page'] = $pernum = 15; 
  5. $config ['uri_segment'] = 3; 
  6. $config ['use_page_numbers'] = TRUE; 
  7. $config ['first_link'] = '第一页'
  8. $config ['last_link'] = '最后一页'
  9. $config ['num_links'] = 5; 
  10. $this->pagination->initialize ( $config ); 
  11. if (! $this->uri->segment ( 3 )) { 
  12.     $currentnum = 0; 
  13. else { 
  14.     $currentnum = is_numeric($this->uri->segment ( 3 ))?(intval($this->uri->segment ( 3 ) - 1)) * $pernum:0; 
  15.  
  16. $current_page=is_numeric($this->uri->segment ( 3 ))?intval($this->uri->segment ( 3 )):1; 
  17. if($current_page){ 
  18.     $data ['title'] = '第'.$current_page.'页-留言本-大冶实验高中首届宏志班网站'
  19. }//开源代码Vevb.com 
  20. else
  21.     $data ['title'] = '留言本-大冶实验高中首届宏志班网站'
  22.  
  23. $data ['liuyan'] = $this->ly->getLy ( $pernum$currentnum ); 

其中有两句代码如下:

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

这两句判断了参数是否为数字,防止非法字符输入.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表