我有一个带有html登录表单jQuery和php的脚本一切正常但如果访问者选择记住我,那么即使我使用jQuery window.location.replace('index.php')重新加载页面后cookie也没有设置或工作;仍然没有工作可以任何人请帮助,谢谢
HTML
<form class="login-form" action="" method="POST" name="operator_login">
<div id="loginerror"></div>
<div id="loginsuccess">Login Success!</div>
<input type="text" placeholder="Email" name="adminusers_username"/>
<input type="password" placeholder="Password" name="adminusers_password"/>
<input type="checkbox" name="operator_remember" checked /> Remember me
<button type="submit" name="operator_login">Login</button>
</form>
的jQuery
$(document).ready(function() {
$('.login-form').submit(function(){
var adminusers_username = $('input[name=adminusers_username]'),
adminusers_password = $('input[name=adminusers_password]'),
loginerror = $('#loginerror'),
loginsuccess = $('#loginsuccess');
if ($('input[name=operator_remember]').is(':checked')) {
var operator_remember = 1;
}else{
var operator_remember = 2;
}
$.post('server/login.php', {
'adminusers_username': adminusers_username.val(),
'adminusers_password': adminusers_password.val(),
'operator_remember': operator_remember
},
function(data){
if (data==1) {
loginerror.hide();
loginsuccess.show();
window.location.replace('index.php');
} else {
loginerror.show().html(data);
}
});
return false;
});
});
PHP
session_start();
if ( isset($_REQUEST['adminusers_username'])
&& $_REQUEST['adminusers_username'] !=''
&& isset($_REQUEST['adminusers_password'])
&& $_REQUEST['adminusers_password']!='') {
$postedusername = $_REQUEST['adminusers_username'];
$postedpassword = $_REQUEST['adminusers_password'];
$rememberme = $_REQUEST['operator_remember'];
$query_rsUserLogin = "SELECT * FROM adminusers
WHERE adminusers_username = '".trim($postedusername)."'";
$rsUserLogin = mysql_query($query_rsUserLogin, $connection);
$row_rsUserLogin = mysql_fetch_assoc($rsUserLogin);
$totalRows_rsUserLogin = mysql_num_rows($rsUserLogin);
$username = $row_rsUserLogin['adminusers_username'];
$userpassword = $row_rsUserLogin['adminusers_password'];
$email_conf = $row_rsUserLogin['admin_email_confirmed'];
$user_status = $row_rsUserLogin['admin_status'];
if ($totalRows_rsUserLogin > 0 ) {
if ($user_status == 'Active' ) {
if ($email_conf == 'Yes' ) {
if ($postedusername === $username
&& $postedpassword === $userpassword ){
if ($rememberme==1){
setcookie("adminusers_username", $username);
echo 1;
}else{
$_SESSION['adminusers_username'] = $username;
echo 1;
}
}else {
echo 'Password Incorrect!.';
}
}else{
echo 'email not confirmed!.';
}
}else{
echo 'acount closed!.';
}
}else {
echo 'email not exist!.';
}
}else {
echo 'insert Username and Password!.';
}
答案 0 :(得分:1)
变化
&& $_REQUEST['adminusers_password']!=0) {
到
&& $_REQUEST['adminusers_password']!='') {