想要在成功登录时重定向到某个页面我正在使用jQuery表单插件来提交我的表单。一切正常但响应被打印而不是重定向。
登录表单使用jquery表单插件提交
<script>
$(document).ready(function(){
// Form submit via jQuery form plugin
$('#formUserSignIn').ajaxForm(function(response){
if(parseInt(response) !== 1){
$('#flashMessage').html(response);
}
else{
window.location.href='/apps/home/dashboard';
}
});
});
</script>
process.php
if(isset($_POST['btnUserSignIn'])){
$userEmail = mysqli_real_escape_string($conn, $_POST['txtUserEmail']);
$userPass = mysqli_real_escape_string($conn, $_POST['txtUserPassword']);
$userPass = $encrypt->hash_pass($userPass);
$sql_check_user = $conn->query("SELECT * FROM workflow_users
WHERE user_email = '$userEmail' AND user_pass = '$userPass'")
or die(query_error('queryCheckUser', $conn->error));
if($sql_check_user->num_rows > 0){
$row_check_user = $sql_check_user->fetch_array();
$userName = $row_check_user['user_name'];
/*
|-----------------------------------------------------
| SET PHP SESSION FOR CURRENT USER
|-----------------------------------------------------
*/
// Set session name
session_name('currentuser');
// Set session expire time
ini_set('session.gc_maxlifetime', 7200);
// Start php session
session_start();
// Store query result to session array
$_SESSION['user_id'] = $row_check_user['user_id'];
$_SESSION['user_name'] = $row_check_user['user_name'];
$_SESSION['user_email'] = $row_check_user['user_email'];
$_SESSION['user_pass'] = $row_check_user['user_pass'];
$_SESSION['user_type'] = $row_check_user['user_type'];
$_SESSION['user_status'] = $row_check_user['user_status'];
$_SESSION['user_otp'] = $row_check_user['user_otp'];
return 1;
}
else{
$msg->set_flash_msg("Error", "Incorrect email or password.");
}
}
答案 0 :(得分:0)
当您调用ajax而不是echo
return
if(isset($_POST['btnUserSignIn'])){
$userEmail = mysqli_real_escape_string($conn, $_POST['txtUserEmail']);
$userPass = mysqli_real_escape_string($conn, $_POST['txtUserPassword']);
$userPass = $encrypt->hash_pass($userPass);
$sql_check_user = $conn->query("SELECT * FROM workflow_users
WHERE user_email = '$userEmail' AND user_pass = '$userPass'")
or die(query_error('queryCheckUser', $conn->error));
if($sql_check_user->num_rows > 0){
$row_check_user = $sql_check_user->fetch_array();
$userName = $row_check_user['user_name'];
/*
|-----------------------------------------------------
| SET PHP SESSION FOR CURRENT USER
|-----------------------------------------------------
*/
// Set session name
session_name('currentuser');
// Set session expire time
ini_set('session.gc_maxlifetime', 7200);
// Start php session
session_start();
// Store query result to session array
$_SESSION['user_id'] = $row_check_user['user_id'];
$_SESSION['user_name'] = $row_check_user['user_name'];
$_SESSION['user_email'] = $row_check_user['user_email'];
$_SESSION['user_pass'] = $row_check_user['user_pass'];
$_SESSION['user_type'] = $row_check_user['user_type'];
$_SESSION['user_status'] = $row_check_user['user_status'];
$_SESSION['user_otp'] = $row_check_user['user_otp'];
echo 1; // echo 1 if success
}
else{
echo "error"; // echo error or any thing else if there is an error
$msg->set_flash_msg("Error", "Incorrect email or password.");
}
}