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环境配置之CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI比较?

什么是CGI   CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务...

PHP memcache扩展的三种安装方法

关于比较请看http://code.google.com/p/memcached/wiki/PHPClientComparison。推荐使用新的memcached,安装方法基本同下面,只...

PHP中的日期处理方法集锦

本文包含以下内容:  1、 得到目前的日期和时间-我们有多少种方式?  2、 改变日期显示的方式-日期和时间的显示形式  3、 ...

PHP计算指定日期所在周的开始和结束日期的方法

本文实例讲述了PHP计算指定日期所在周的开始和结束日期的方法。分享给大家供大家参考。具体实现方法如下: <html> <head> <title>...

php基于curl主动推送最新内容给百度收录的方法

本文实例讲述了php基于curl主动推送最新内容给百度收录的方法。分享给大家供大家参考,具体如下: php curl的好处可以以最快的方式并且模仿post提供我们的url地址给百度搜索引...