可能重複:
Do I have to use mysql_real_escape_string if I bind parameters?快速庫MySQLi安全問題
我有相關的問題,一個快速的MySQLi安全...
例如,看看這個代碼(從用戶那裏獲得輸入,並根據數據庫檢查它是否存在用戶名/密碼組合):
$input['user'] = htmlentities($_POST['username'], ENT_QUOTES);
$input['pass'] = htmlentities($_POST['password'], ENT_QUOTES);
// query db
if ($stmt = $mysqli->prepare("SELECT * FROM members WHERE username=? AND password = ?"))
{
$stmt->bind_param("ss", $input['user'], md5($input['pass'] . $config['salt']));
$stmt->execute();
$stmt->store_result();
// check if there is a match in the database for the user/password combination
if ($stmt->num_rows > 0)
{}
}
在這種情況下,我在表單數據上使用htmlentities(),並使用MySQLi準備好的語句。我還需要使用mysql_real_escape_string()嗎?
我想我還應該問......除了使用MySQLi準備的語句和htmlentities()還有什麼我應該做的,安全明智嗎? – 2010-05-23 19:08:26
這不是編輯你的原始問題,但足夠好:) – 2010-05-23 19:11:06
'htmlentities'旨在顯示給客戶端。你不應該真的在數據庫查詢中使用它 - 這是多餘的。 – ceejayoz 2010-05-23 19:11:36