<?php
//This should be called first, but ONLY if it is required, or it will corrupt your data.
//This must be done before you manipulate the data in any other way.
//Generally, this is used on the data if your server has magic quotes on.
//I've added code to detect if it is on or not.
$ad_title = (get_magic_quotes_gpc()) ? stripslashes($ad_title) : $ad_title;
//This line is fine, but only do it if you know it is necessary, because it is changing your data.
//If you are doing it just because you were receiving an SQL error, I would recommend you comment this out.
$ad_title = htmlentities($ad_title);
//This should be the last thing you do to your data before using it in SQL.
//This will take care of all required escaping, and protect you from SQL injection.
$ad_title = mysql_real_escape_string($ad_title);
?>
不聽@mikelbring該解決方案將讓你容易受到SQL注入。 – dqhendricks 2012-03-21 20:38:57
@mikelbring:** NO ** addslashes是完全廢話,應該從PHP中刪除。 – 2012-03-21 20:39:06
如果你使用'mysql_real_escape_string',你不需要'addslashes'(當然不是'stripslashes'。建議:閱讀文檔 – 2012-03-21 20:39:27