わかりました、AJAX 経由でログイン ページを作成しています。いくつかの奇妙な理由で。以下のAJAX POSTページ。
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/user.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/db.php');
$db = dblogin();
$email = $_POST['email'];
$pass = $_POST['pass'];
$query = "SELECT * FROM `user` WHERE `email`='".$email."'";
$res = $db->query($query);
if($res->num_rows!='0'){
if($res->num_rows=='1'){
$list=$res->fetch_assoc();
}
}else{
$list = false;
}
$invalid = <<<_END
<form>
<table>
<caption>Invalid credentials, please try again.</caption>
<tr>
<td>Email:</td><td><input type='email' id='email' name='email' /></td>
</tr>
<tr>
<td>Password:</td><td><input type='password' id='password' name='password' /> </td>
</tr>
<tr><td colspan='2' align='center'><input type='button' onclick="login()" value="Log In"></td></tr>
</table>
</form>
_END;
//if the return is false, this executes, which states that the email is not found
//and prompts for a new login
/*if ($list == false){
$query = "INSERT INTO `failloglog` (`ip`,`email`) VALUES ('".$_SERVER['REMOTE_ADDR']."','".$email."')";
$db = dblogin();
$db->query($query);
echo $invalid;
}*/
//otherwise, it compares the passwords
//else{
if (pass_compare($pass,$list['password'])){
cookify($email);
echo "success";
}
else{
//$query = "INSERT INTO `failloglog` (`ip`,`email`) VALUES ('".$_SERVER['REMOTE_ADDR']."','".$email."')";
//$db = dblogin();
//$db->query($query);
echo $invalid;
}
//}
?>
だけを提供する代わりに、完全にフォーマットされた html ページを提供し$invalid
ています。console.log(response)
ページはこちらhttps://www.dropbox.com/s/hmejactu54891p6/response.txt
これが jQuery 呼び出しです。
function login()
{
var email = $('#email').val();
var pass = $('#password').val();
$('#login').html('<img src="img/pleasewait.gif" id="pleasewait"/>');
$.ajax({
url: "http://$location/lib/ajax/login.php",
type: "POST",
data:{
email: email,
pass: pass
}
})
.always(function(response){
console.log(response);
if(response=="success"){
location.href = "http://$location/home.php";
}
else{
$('#login').html(response);
}
});
}
助言がありますか?