如何从PHP if else语句运行返回登录文件和运行jQuery函数


How to run return to login file and run jQuery function from PHP if else statement

我有下面的PHP if/else语句-我如何告诉它返回login.PHP并运行jQuery函数?

if($result) {
        if(mysql_num_rows($result) == 1) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
            $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
            $_SESSION['SESS_LOGIN'] = $member['login'];
            session_write_close();
            header("location: ../index.php");
            exit();
        }else {
            $error = true;
                    // go back to login.php and run jQuery function
            }
    }else {
        die("Query failed");
            // // or go back to login.php and run different jQuery function

    }

您可以使用:

header('Location: login.php?message=query_failed');

header('Location: login.php?message=login_failed');

以及在login.php上的javascript tags:

您可以将php用于:

<?php if($_GET['message'] == 'query_failed'):  ?>
jquery_query_failed_function();
<?php elseif($_GET['message'] == 'login_failed'):  ?>
jquery_login_failed_function();
<?php endif; ?>

所以继续你的else声明:它应该是:

继续你的其他声明:

else {
        $error = true;
        header('Location: login.php?message=login_failed');
        }
}else {
    header('Location: login.php?message=query_failed');
    die("Query failed");
        // // or go back to login.php and run different jQuery function

}
header("Location: ../login.php?error_code=1");
header("Location: ../login.php?error_code=2");

根据错误代码,如果你想使用重定向,你会执行一个不同的函数。