我終於做出了我認爲是一種很好,安全和快速的方式來執行查詢,但我希望在我將其全部實施到網站之前完全確定。MySQL/PHP - 這是一個好的和安全的方式逃脫querys?
我的代碼:
$email = $_POST['email'];
$displayName = $_POST['displayName'];
$pass = $_POST['pass1'];
if($stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password) VALUES (?, ?, md5(?))")) {
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("sss", $email, $displayName, $pass);
/* Execute it */
$stmt -> execute();
echo "You are now registered.<br />";
echo "<a href=\"login.php\">Login</a>";
/* Close statement */
$stmt -> close();
}
順便說一句,這是什麼stmt是平均/代表什麼?
編輯,新建CODE:
/* Create a prepared statement */
$stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password,
dateRegistered) VALUES (?, ?, md5(?), NOW())");
if (false===$stmt) {
die('prepare() failed: ' . htmlspecialchars($link->error));
}
$rc = $stmt -> bind_param("sss", $email, $displayName, $pass);
if (false===$rc) {
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}
/* Execute it */
$rc = $stmt->execute();
if (false===$rc) {
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
echo "You are now registered.<br />";
echo "<a href=\"login.php\">Login</a>";
/* Close statement */
$stmt -> close();
stmt =語句 – 2012-07-13 22:37:32
謝謝,應該想通了。 :P – 2012-07-13 22:38:35
你不應該使用md5()作爲密碼,它不再安全。 (並且沒有使用鹽從未安全)。您應該*總是*在PHP端執行散列操作,否則密碼可能會在MySQL日誌文件中結束。 – Jacco 2012-07-16 09:54:06