Здравствуйте вот код формы:
<form id="loginform" method="POST">
<input type="hidden" name="KeyLogin" value="<?=$LoginKey?>">
<div id="pinCode">
<input id="pin1" class="ss" type="password" maxlength="1" name="pass1" autofocus>
<input class="ss" type="password" maxlength="1" name="pass2">
<input class="ss" type="password" maxlength="1" name="pass3">
<input class="ss" type="password" maxlength="1" id="input4" name="pass4">
</div>
<input type="submit" name="do_login" id="loginBtn" style="display: none;" value="Login"/>
</form>
Вот код ajax:
$('#loginform').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: 'login.php',
data: $(this).serialize(),
success: function(response)
{
var jsonData = JSON.parse(response);
if (jsonData.success == "1")
{
location.href = 'my_profile.php';
}
else
{
alert('Invalid Credentials!');
}
}
});
});
Вот код login.php
<?
require_once "../../lib/start.php";
$data = $_POST;
if( isset($data['do_login']) ) {
$user = R::findOne('users', 'login = ?', array($data['KeyLogin']));
if ($user) {
$password = $data['pass1'].$data['pass2'].$data['pass3'].$data['pass4'];
if (password_verify($password, $user->password)){
$user->last_login = time();
$user->key_status = 1;
R::store($user);
$_SESSION['logged_user'] = $user;
echo json_encode(array('success' => 1));
} else {
echo json_encode(array('success' => 0));
}
}
}
?>
Почему данный код не работает?