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

相关文章

wordpress之wp-settings.php

接上面开始wp-config.php,wp-settings.php这两个文件,wp-config.php故名恩意配置文件所以没什么可解释的。 wp-settings.php最上在的函数...

php中的常用魔术方法汇总

这篇文章详细的对php中的常用魔术方法进行了整理归纳,分享给大家供大家参考,具体内容如下 1、PHP把所有”__”开头的方法当做魔术方法,所以任何自定义的方法都不能是”__”开头 php...

php使用sql数据库 获取字段问题介绍

在PB开发过程中,由于数据库中使用了 ntext字段,出现以下提示错误,郁闷了很长时间找不到解决方案,后查阅大量资料,终于明白:PB报错: 不能用 DB-Library(如 ISQL)或...

php写入数据到CSV文件的方法

本文实例讲述了php写入数据到CSV文件的方法。分享给大家供大家参考。具体实现方法如下: <?php $row = 0; ini_set('max_execution_...

一个php生成16位随机数的代码(两种方法)

分享一个php生成16位随机数的代码,php生成随机数的二种方法。 方法1 复制代码 代码如下: <?php $a = mt_rand(10000000,99999999)...