次のような状況があります。
index.html (私のログインページです)
<div data-role="page" id="page_login">
<div id="wrapper_top_image">
<div id="top_image"></div>
</div>
<div data-role="content" data-theme="b">
<div id="landmark-1" data-landmark-id="1">
<form id="loginForm" onsubmit="return submitLogin();">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" placeholder="Username" />
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" placeholder="Password" />
</div>
<input type="submit" value="Login" id="submitButton">
</form>
</div>
</div>
<div data-role="footer">
<h4>© 2013 Company</h4>
<h6>Developed by Alex</h6>
</div>
そして、すべてをチェックするPHPスクリプト-> ps ..すでにインジェクションを回避するように修正しました! :
auth.php
$mysqli = new mysqli($mysql_hostname,$mysql_user, $mysql_password, $mysql_database);
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {
$username =$_POST['username'];
$password =$_POST['password'];
$sql = "SELECT id, password, username FROM users WHERE username='$username' AND password='$password' LIMIT 1";
$result = $mysqli->query($sql) or die( $mysqli->error() );
$rowN= mysqli_num_rows($result);
if($rowN==1){
$response_array['status'] = 'success';
} else {
$response_array['status'] = 'error';
}
echo json_encode($response_array);
}
$mysqli->close();
最後に私の JQuery スクリプト:
function submitLogin(){
jQuery.support.cors = true;
$.ajax({
url: 'http://www.xxxx.com/mobile/auth.php',
crossDomain: true,
type: "post",
data: $("#loginForm").serialize(),
success: function(data){
if(data.status == 'success'){
//alert("Granted Access!");
$.mobile.changePage("main.html");
}else if(data.status == 'error'){
alert("Authentication Invalid. Please try again!");
navigator.app.exitApp();
$.mobile.changePage("index.html");
}
}
});
};
すべて正常に動作しています!データがチェックされ、問題がない場合は main.html (メイン ページ) にリダイレクトされます。それ以外の場合、アプリは認証が間違っていることを示すウィンドウをポップアップ表示し、ユーザーを同じページに保持します。
ここにジレンマがあります: ユーザーが再度ログインしようとして間違った資格情報を入力した場合、そのユーザーが入力した資格情報は、たとえ正しいものを入力したとしても無効になり、更新するまでアプリはログイン ページに戻り続けます。デバイスで実行している場合は、ブラウザを終了するか、アプリを終了します。
何が起こっているのか知っている人はいますか?