我有以下的HTML文件,用戶將輸入他們的用戶名和密碼,然後單擊提交按鈕。提交後登錄
<form Name ="form1" Method ="POST" ACTION = "userlogin.php" id="form1">
<div id="main_body" class="full-width">
<label>Username:</label>
<input type = "text"
id = "usernameLogin"
name="pat_username">
<label>Password:</label>
<input type = "password"
id = "passwordLogin"
name="pat_password">
<input type="submit" onclick="click_button_login()" value="Login" name="submit" id="submit"/>
</div>
</form>
PHP文件應該連接到我的數據庫並檢查輸入的用戶詳細信息是否正確。數據庫連接在那裏,因爲我以前測試過。一旦用戶點擊提交按鈕會出現這樣的錯誤:Cannot POST /http-services/emulator-webserver/ripple/userapp/x/C/xampp/htdocs/xampp/glove_project_php/www/userlogin.php
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$newUsername = mysqli_real_escape_string($conn, $_POST['pat_username']);
$newPassword = mysqli_real_escape_string($conn, $_POST['pat_password']);
$result = $conn->query("SELECT * FROM tablename WHERE patient_username ='$newUsername' AND patient_password='$newPassword'");
if (mysqli_num_rows($result)) {
header("Location: mainmenu.html");
}
else
{
header("Location: index.html");
}
$conn->close();
}
?>
有沒有調用這個PHP文件到模擬器上進行工作以不同的方式?這段代碼在localhost上完美工作。
例如[你的腳本是對SQL注入攻擊的風險。(http://stackoverflow.com/questions/60174/how-can- i-prevent-sql -injection-in-php)瞭解[MySQLi]的[準備](http://en.wikipedia.org/wiki/Prepared_statement)聲明(http://php.net/manual/en/) mysqli.quickstart.prepared-statements.php)。 –
請使用PHP的[內置函數](http://jayblanchard.net/proper_password_hashing_with_PHP.html)來處理密碼安全性。如果您使用的PHP版本低於5.5,則可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。 –