無法使用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