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中文URL编解码(urlencode()rawurlencode()

下面是详细解释:///\\\ string urlencode ( string str) 返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十...

php设计模式 Adapter(适配器模式)

复制代码 代码如下: <?php /** * 适配器模式 * * 将一个类的接口转换成客户希望的另外一个接口,使用原本不兼容的而不能在一起工作的那些类可以在一起工作 */ // 这...

PHP中soap用法示例【SoapServer服务端与SoapClient客户端编写】

本文实例讲述了PHP中soap用法。分享给大家供大家参考,具体如下: 一、首先要设置服务器环境 修改php.ini 得添加extension=php_soap.dll (加载soap 内...

PHP从零开始打造自己的MVC框架之路由类实现方法分析

PHP从零开始打造自己的MVC框架之路由类实现方法分析

本文实例讲述了PHP从零开始打造自己的MVC框架之路由类实现方法。分享给大家供大家参考,具体如下: 在core目录下,新建一个名为lib的子目录,然后把我们前面写个route.php这个...

浅谈ThinkPHP的URL重写

我想要的结果无非是去掉URL路径中的index.php 首先是配置.htaccess 复制代码 代码如下: <IfModule mod_rewrite.c> RewriteE...