无法使用PDO。净化数据PHP功能
我在这里读了很多的问题,这是我第一次尝试做一些事情的人我的办公室外面,所以我需要消毒的数据输入,研究一下发现这个功能。
function clean_data($input){
$input = trim(htmlentities(strip_tags($input,",")));
if (get_magic_quotes_gpc())
$input = stripslashes($input);
$input = mysql_real_escape_string($input);
return $input;
}
例如:
其确定该功能来净化数据?
这种方法很可怕,会破坏和破坏数据。只需使用适当的卫生方法对数据进行清理即可使用。例如。 'mysql_real_escape_string()'在运行'mysql_query()'之前。或者在输出网页上的任何内容之前使用'htmlentities()'。但是,PDO或mysqli真的是有益的 –
因此,使用此代码即时避免SQL注入, '$ sql =“INSERT INTO clientes VALUES(NULL,:iduser,:nombre,:cedula,:dir,:tel)”; $ query = $ db-> prepare($ sql); $ query-> execute( ':iduser'=>($ _ POST ['id']), ':nombre'=>($ _ POST ['nombre']), ':cedula'=> ($ _ POST ['cedula']), ':dir'=>($ _ POST ['dir']), ':tel'=>($ _ POST ['tel']), )'' – CCortina