这是我的问题。每个用户应具有特定的“仪表板”,如果用户未登录,则应将其阻止。因此user1 ==> login ==>转到dasboard 1等。仪表板位置保存在mysql数据库的特定字段中。我在php中使用login / sigup表单,因此有效。当用户登录时,进入欢迎页面。我希望从db中的链接中添加iframe /内容,以便该会话用户可见。
我尝试加载会话元素并显示它,但是它不起作用,并且没有出现任何错误。
if($stmt->execute()){
// Check if username exists, if yes then verify password
if($stmt->rowCount() == 1){
if($row = $stmt->fetch()){
$id = $row["id"];
$page = $row["location"];
$username = $row["username"];
$hashed_password = $row["password"];
if(password_verify($password, $hashed_password)){
// Password is correct, so start a new session
session_start();
// Store data in session variables
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["location"] = $page;
// Redirect user to welcome page
header("location: welcome.php");
这是welcome.php
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: log.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body{ font: 14px sans-serif; text-align: center; }
</style>
</head>
<body>
<div class="page-header">
<h1>Hi, <b><?php echo htmlspecialchars($_SESSION["username"]); ?> </b>. Welcome to our site.</h1>
</div>
<?php echo $_SESSION ["location"]; ?>
<p>
<a href="reset-password.php" class="btn btn-warning">Reset Your Password</a>
<a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
</p>