网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/10/14 浏览:3 次 )

本文实例讲述了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 ))"codetitle">复制代码 代码如下:$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程序设计有所帮助。

上一篇:为PHP安装imagick时出现Cannot locate header file MagickWand.h错误的解决方法
下一篇:详解PHP导入导出CSV文件