Reputation: 2018
I have an ajax login on my site and for some strange reason, it won't work in internet explorer yet it works in Webkit, latest version of FireFox, and Opera. So I don't think it is my code but is there a known problem with ajax requests for IE? Thanks!
Javascript:
$('.mainlogin').submit(function() {
var username = $('#main_username').val();
var password = $('#main_pword').val();
$.ajax({
url: 'log.php',
type: 'POST',
data: {
user: username,
pass: password
},
success: function(response) {
if (response == 'success') {
window.location.reload();
} else {
$('.logerror').fadeIn(250);
}
}
});
return false;
});
PHP:
<?php
require_once('.conf.php');
$user = mysql_real_escape_string($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);
$result = mysql_query("SELECT * FROM accountController WHERE username = '$user'");
while ($row = mysql_fetch_array($result)) {
if (sha1($user.$pass) == $row['pword']) {
session_start();
$_SESSION['login'] = 1;
$_SESSION['uname'] = $row['username'];
$_SESSION['id'] = $row['id'];
echo "success";
}
}
?>
Upvotes: 0
Views: 1872
Reputation: 18595
Becuase IE8:
"uses the first session cookie set and not the last as in Firefox."
http://anvilstudios.co.za/blog/php/session-cookies-faulty-in-ie8/
To fix this problem all you need to do is set:
session_regenerate_id(true);
Which deletes old session id and forces IE8 to use the new one.
Caching may be the problem, try adding:
cache: false,
success: function(response) {
if (response == 'success') {
document.getElementById('status').innerHTML=http.responseText;
}
Upvotes: 1