PHP分页参数过滤实例
本例详细解析了PHP在处理SQL注入时,如何对分页参数实施过滤的具体方案,供开发者参考借鉴。
基于网络安全原则,网络端接收的任何输入数据均不可信,必须执行严格的参数清洗。以下通过具体代码案例加以说明。
复制代码 代码如下:$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; 上述两行代码核心在于检测参数是否为数值型,以此拦截非数字的非法字符输入。
期望上述关于PHP程序设计的技巧能为读者提供实际帮助。