這是在運行數據庫查詢之前防止SQL注入的好方法嗎?使用mysql_real_escape_string和stripslashes避免SQL注入
$name = mysql_real_escape_string(stripslashes($name));
$age = mysql_real_escape_string(stripslashes($age));
$location = mysql_real_escape_string(stripslashes($location));
在此先感謝!
爲什麼你需要'stripslashes'以及如何使用[PDO](http://php.net/manual/en/book.pdo.php)? – 2012-02-22 11:34:55
簡短的回答 - 不,不是。不要使用'mysql_ *'函數,但使用PDO,就像@Click建議的那樣。 – 2012-02-22 11:38:42
你的代碼打破了最近/正確配置(魔術引號禁用)PHP安裝中包含反斜槓的任何字符串。切勿無條件使用'stripslashes'。只有當'get_magic_quotes_gpc()'存在並返回'true'時才使用它! – ThiefMaster 2012-02-22 12:27:12