当前位置:首页 > PHP教程 > php应用 > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2021-04-21 11:48:57 浏览: 评论:0 

这篇文章主要介绍了php防止sql注入中过滤分页参数的方法,实例展示了针对分页参数的数值判断问题,是非常具有实用价值的技巧,需要的朋友可以参考下

本文实例讲述了php防止sql注入中过滤分页参数的方法。分享给大家供大家参考。具体分析如下:

就网络安全而言,在网络上不要相信任何输入信息,对于任何输入信息我们都必须进行参数过滤。对此,我们先来看看下面的实例:

  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.  
  17. $current_page=is_numeric($this->uri->segment ( 3 ))?intval($this->uri->segment ( 3 )):1; 
  18. if($current_page){ 
  19.     $data ['title'] = '第'.$current_page.'页-留言本-防SQL注入测试'; 
  20. } 
  21. else{ 
  22.     $data ['title'] = '留言本-防SQL注入测试'; 
  23. } 
  24.  
  25. $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; 

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

希望本文所述对大家的PHP程序设计有所帮助。

Tags: php防止sql注入

分享到: