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

yipeiwu_com6年前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的Yii框架中的Controller控制器

控制器是 MVC 模式中的一部分, 是继承yii\base\Controller类的对象,负责处理请求和生成响应。 具体来说,控制器从应用主体接管控制后会分析请求数据并传送到模型, 传送...

PHP7匿名类的用法示例

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

php数组函数序列之array_slice() - 在数组中根据条件取出一段值,并返回

array_slice()定义和用法 array_slice() 函数在数组中根据条件取出一段值,并返回。 注释:如果数组有字符串键,所返回的数组将保留键名。(参见例子 4) 语法 ar...

PHP中常用的转义函数

1. addslashesaddslashes对SQL语句中的特殊字符进行转义操作,包括(‘), (“), (), (NUL)四个字符,此函数在DBMS没有自己的转义函数时候使用,但是如...

基于yaf框架和uploadify插件,做的一个导入excel文件,查看并保存数据的功能

基于yaf框架和uploadify插件,做的一个导入excel文件,查看并保存数据的功能

思路: 1.首先,页面前端,上传附件,提交给后台,并带一个随机性的参数(可以用时间戳); 2.后端接收附件,做一系列的逻辑处理,无误后,将对应的文件存储在上传的目录下; 3.然后前端,上...