哦,天哪,另一件事 IE 显然做得不好。
我在标题中说“偶尔工作”,因为我实际上已经能够让代码在 IE 中工作,但有时(没有任何代码更改)它没有工作,显然同样适用我的一位客户。
我的临时解决方案是告诉他“停止使用 IE”,但与此同时,我觉得我有责任进行调查。
问题: 登录过程似乎有点混乱,然后停止,没有抛出通常伴随错误用户名或密码的错误消息。这仅在 IE 中(我的版本是 IE9,但我不能保证此问题仅限于该版本)。登录在所有其他经过测试的浏览器中都能完美运行,包括移动浏览器。
Javascript:
$('#login-box > form').submit(function(){
$('#login-response').html("<img src='assets/images/wait.gif' height='32' />");
var str = $(this).serialize();
$.ajax({
type: 'POST',
url: 'lib/check-login.php',
data: str,
cache: false,
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(errorThrown + '\n' + textStatus);
},
success: function(msg) {
var output = msg.split('|');
var delay = 1600;
if (output[0] == 'OK') {
if (output[1] == '') { //no referrer, redirect to home page
window.location = home_page;
}
else { //referrer set, redirect back to referring page
console.log('saying referer');
//window.location = output[1].substring(1);
window.location = home_page;
}
}
else {
$('#login-response').html('no, denied');
$('#login-box input').val('');
$('#login-box input#username').focus();
}
}
});
return false;
});
PHP:
<?php
$sess = session_id();
if ($sess == '')
session_start();
require_once('config.php');
try_login($_POST['username'], $_POST['password']);
/****** user has submitted credentials, check them and return value to javascript (AJAX) ***/
function try_login($u, $p) {
global $mysqli;
$res = $mysqli->query(' select u.user_id, u.user_name, u.user_pass, s.salt, ifnull(u.team_id,0) team_id
from users u left join seasoning s on u.user_id = s.user_id
where u.user_name = \'' . $mysqli->real_escape_string($u) . '\'
limit 1;') or die($mysqli->error);
$row = $res->fetch_assoc();
if($row['user_pass'] == crypt($p,$row['salt'])) { //correct password, log user in
if (isset($_POST['remember'])) //keep user logged in
$duration = time()+60*60*24*365;
else //end user session when he closes browser
$duration = false;
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['team_id'] = $row['team_id'];
$mysqli->query("update users
set
last_login = '" . date('Y-m-d H:i:s') . "',
login_qty = login_qty + 1
where user_id = " . $_SESSION['user_id'] . ";") or die($mysqli->error);
$mysqli->query("insert into
activity ( activity_type_id,
user_id)
values (8,
" . $_SESSION['user_id'] . ");") or die($mysqli->error);
echo 'OK|' . $_SESSION['last_page'];
}
else { //login failed
echo 'FAIL';
}
}
?>