Home > php教程 > php手册 > body text

php中$_GET与$_POST过滤sql注入的方法,_get_post

WBOY
Release: 2016-06-13 09:22:26
Original
1601 people have browsed it

php中$_GET与$_POST过滤sql注入的方法,_get_post

本文实例讲述了php中$_GET与$_POST过滤sql注入的方法,分享给大家供大家参考。具体分析如下:

此函数只能过滤一些敏感的sql命令了,像id=1这种大家还是需要自己简单过滤了。

主要实现代码如下:

复制代码 代码如下:

if (!get_magic_quotes_gpc())
{
if (!empty($_GET))
{
$_GET  = addslashes_deep($_GET);
}
if (!empty($_POST))
{
$_POST = addslashes_deep($_POST);
}
$_COOKIE   = addslashes_deep($_COOKIE);
$_REQUEST  = addslashes_deep($_REQUEST);
}
function addslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}
}

希望本文所述对大家的PHP程序设计有所帮助。

php过滤sql注入,新手

我在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......余下全文>>
 

php 对于thinkphp的防sql注入跟过滤问题

用着个过滤传过来的值,这两个用之前先判断是否开启了
get_magic_quotes_gpc();没有开启的话用以下两个都可以过滤
mysql_real_escape_string();一般用于sql语句
addslashes();
例如:
if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST[‘lastname’]);
//或者mysql_real_escape_string($_POST[‘lastname’])
} else {
$lastname = $_POST[‘lastname’];
}
 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template