12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
网络知识 时间:2024-12-03 15:10:03
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
php请求数据防sql注入的方法:1.mysql_real_escape_string,转义sql语句中使用字符串中的特殊字符2.使用addslashes()函数将php.ini中的“magic_quotes_gpc = Off”这个设置打开
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
php请求数据防sql注入的方法:
1.mysql_real_escape_string,转义sql语句中使用字符串中的特殊字符
2.使用addslashes()函数将php.ini中的“magic_quotes_gpc = Off”这个设置打开,例如:
$sql = "select count(*) as ctr from users where username
='".mysql_real_escape_string($username)."' and
password='". mysql_real_escape_string($pw)."' limit 1";
3.可自定义函数进行防止,例如:
/**
* 防止sql注入自定义方法一
* @param: mixed $value 参数值
*/ function check_param($value=null) {# select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile$str = 'select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile';
if(!$value) {exit('没有参数!');}elseif(eregi($str, $value)) {exit('参数非法!');}return true;}
/**
* 防止sql注入自定义方法二
* @param: mixed $value 参数值
*/function str_check( $value ) {if(!get_magic_quotes_gpc()) {// 进行过滤$value = addslashes($value);
}
$value = str_replace("_", "\_", $value);
$value = str_replace("%", "\%", $value);
return $value;}
/**
* 防止sql注入自定义方法三
* @param: mixed $value 参数值
*/
function post_check($value) {if(!get_magic_quotes_gpc()) {
// 进行过滤 $value = addslashes($value);
}$value = str_replace("_", "\_", $value);
$value = str_replace("%", "\%", $value);
$value = nl2br($value);
$value = htmlspecialchars($value);
return $value;}
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19