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

yipeiwu_com5年前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程序设计有所帮助。

相关文章

PHP批量修改文件名称的方法分析

本文实例讲述了PHP批量修改文件名称的方法。分享给大家供大家参考,具体如下: 在这里我们利用一个战地自己写的一个例子来具体分析一下利用PHP批量修改文件名称的思路和注意事项。 从这个例子...

PHP file_exists问题杂谈

PHP file_exists问题杂谈

问题   公司有个框架是基于smarty写的,我负责php的升级,维护人员把新环境布上来之后,测试人员找我提出经常报错(错误:提示找不到文件的)。   我追踪了一下代码,原来是smart...

PHP命名空间namespace定义及导入use用法详解

本文实例讲述了PHP命名空间namespace定义及导入use用法。分享给大家供大家参考,具体如下: 在PHP中,出现同名函数或是同名类是不被允许的。为防止编程人员在项目中定义的类名或函...

php关闭warning问题的解决方法

error_reporting 设定错误讯息回报的等级 2047我记得应该是E_ALL。 php.ini 文件中有许多配置设置。您应当已经设置好自己的php.ini 文件并把它放在合适的...

PHP7匿名类的用法示例

本文实例讲述了PHP7匿名类的用法。分享给大家供大家参考,具体如下: <?php /** * Created by PhpStorm. * User: Itboot...