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获取手机端的号码以及ip地址实例代码

我们在用PHP写移动端程序的时候,有的时候需要直接获取手机号码以及对应的IP地址内容,在此我们给大家整理了详细完整的代码内容,需要的朋友们测试下。 <?php /**...

PHP 多进程 解决难题

而且, 如果输入数据非法, 而脚本没有检测, 导致abort, 也会让你很不开心. 那? 怎么办呢? 呵呵, 别着急, 多进程来帮您! 那,这是为什么呢? 优点: 1. 使用多进程, 子...

PHP7.1安装yaf扩展的方法

把PHP命令加到系统 我的PHP安装目录是/usr/local/webserver/php,所以phpize是/usr/local/webserver/php/bin/phpize,但是...

用PHP实现Ftp用户的在线管理的代码

领导要我策划一个网页设计大赛和Flash创作大赛,要求必须实现在线报名和上传作品。通过FreeBSD+Apache+PHP+Mysql+FTP我实现了该要求。 实现在线报名和上传作品的思...

在Mac上编译安装PHP7的开发环境

在Mac上编译安装PHP7的开发环境

今天看到鸟哥发微博说php7 beta1测试版发布了,于是赶紧就去抢先下载,把自己的开发环境也升级到PHP7去,话不多少,下面就一起来搞起吧。。。 首先你得去官网下载php7 beta...