【发布时间】:2019-10-29 23:57:37
【问题描述】:
如果用户在登录后转到 login.html,我会尝试将用户路由到 client_portal.php。
尝试创建包含会话信息的第三个 .php 文件并测试是否设置了 login_user
尝试使用 jQuery "window.location.replace();"每次自动路由用户
这是来自第三个 PHP 文件 checkLogin.php 的代码
include("session.php");
if (isset($_SESSION['login_user'])) {
header("Location: client_portal.php");
die();
}
这是来自 session.php -- DB 是实际信息的占位符(这是私有的)
$link = mysqli_connect('DB', 'DB', 'DB', 'DB'); //Connect to the database
session_start();
//Preparing the SQL statements
$stmt1 = mysqli_prepare($link,"SELECT username, first_name FROM login WHERE username =?");
//Binding the SQL statements
mysqli_stmt_bind_param($stmt1, "s", $user_check);
$user_check = $_SESSION['login_user']; //Checking if the user has a login session active
mysqli_stmt_execute($stmt1);
$result = mysqli_stmt_get_result($stmt1); //Get the result
$row = mysqli_fetch_assoc($result); //Setting the array
$_SESSION["login_session"] = $row['username']; //Setting a session under the username
$firstName = $row["first_name"];
if(!isset($_SESSION['login_user'])) {
header("Location: /login");
die();
}
预期:将用户路由到客户端门户 实际:正常加载登录页面
【问题讨论】:
-
应该是
header("Location: client_portal.php");没有: