在我的登录脚本中一切正常。我在我的 div (id=login_reply) 中得到了正确的响应,并且会话开始了。但是每当我刷新页面时,login_reply 就消失了。我怎样才能保留 login_reply?谢谢!
这是php:
if (isset($_POST['username'], $_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(md5($_POST['password']));
$check = mysql_query("SELECT * FROM `userbase` WHERE `user_name` = '$username'");
if (mysql_num_rows($check) > 0)
{
while ($row = mysql_fetch_assoc($check))
{
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$user_email = $row['user_email'];
$user_password = $row['user_password'];
if ($password == $user_password)
{
$_SESSION['user_id'] = $user_id;
if (isset($_SESSION['user_id']) && $_SESSION['user_id'] != '')
echo "Welcome back '$user_name'!";
else
{
echo 'no';
}
}
else
echo 'no';
}
}
else
echo 'no';
}
这是 jQuery
$(document).ready(function()
{
$('#login').click(function()
{
var username = $('#username').val();
var password = $('#password').val();
$.ajax(
{
type: 'POST',
url: 'php/login.php',
data: 'username=' +username + '&password=' + password,
success: function(data)
{
if (data != 'no')
{
$('#logform').slideUp(function()
{
$('#login_reply').html(data).css('color', 'white');
});
}
else
$('#login_reply').html('Invalid username or password').css('color', 'red');
}
});
return false;
});
});