时间:2021-07-01 10:21:17 帮助过:26人阅读
本文实例讲述了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程序设计有所帮助。
我在PHP4环境下写了一个防SQL注入的代码,经过实际使用在PHP5下也兼容,欢迎大家使用修改,使用。
代码如下:
/*
sqlin 防注入类
*/
class sqlin
{
//dowith_sql($value)
function dowith_sql($str)
{
$str = str_replace("and","",$str);
$str = str_replace("execute","",$str);
$str = str_replace("update","",$str);
$str = str_replace("count","",$str);
$str = str_replace("chr","",$str);
$str = str_replace("mid","",$str);
$str = str_replace("master","",$str);
$str = str_replace("truncate","",$str);
$str = str_replace("char","",$str);
$str = str_replace("declare","",$str);
$str = str_replace("select","",$str);
$str = str_replace("create","",$str);
$str = str_replace("delete","",$str);
$str = str_replace("insert","",$str);
$str = str_replace("'","",$str);
$str = str_replace(""","",$str);
$str = str_replace(" ","",$str);
$str = str_replace("or","",$str);
$str = str_replace("=","",$str);
$str = str_replace("%20","",$str);
//echo $str;
return $str;
}
//aticle()防SQL注入函数
function sqlin()
{
foreach ($_GET as $key=>$value)
{
$_GE......余下全文>>
基本上我都是用htmlspecialchars()和mysql_escape_string()这两个方法把获取到的参数处理一下。。
http://www.bkjia.com/PHPjc/904932.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/904932.htmlTechArticlephp防止sql注入之过滤分页参数实例,sql分页 本文实例讲述了php防止sql注入中过滤分页参数的方法。分享给大家供大家参考。具体分析如下:...