用于清理 Mysql 数据库输入的函数
我正在尝试将一个通用函数放在一起,该函数将清理Mysql数据库的输入。到目前为止,这就是我所拥有的:
function sanitize($input){
if(get_magic_quotes_qpc($input)){
$input = trim($input); // get rid of white space left and right
$input = htmlentities($input); // convert symbols to html entities
return $input;
} else {
$input = htmlentities($input); // convert symbols to html entities
$input = addslashes($input); // server doesn't add slashes, so we will add them to escape ',",\,NULL
$input = mysql_real_escape_string($input); // escapes \x00, \n, \r, \, ', " and \x1a
return $input;
}
}
如果我理解了.这由 php 服务器设置为自动转义字符,而不需要使用 。get_magic_quotes_qpc()
addslashes()
我是否一起使用并正确地一起使用,还有其他可以添加的内容来增加消毒。addslashes()
mysql_real_escape_string()
谢谢