一个人登录并创建会话后,如何显示只有登录成员才能看到的元素。我认为可行的是输入我想隐藏的元素的正文:如果它设置了会话名称并且设置了会话 user_id = true,则显示我正在隐藏的当前元素。
<?php
session_start();
?>
<!DOCTYPE html>
<head>
<title> <?php $page_title ?> </title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<script src="jquery-1.10.2.js"></script>
<script src="formValidation.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="login"> <a href="login.php">Login</a> </div>
<h1>Films.com</h1>
<?php if (isset($_SESSION['user_id']) && isset($_SESSION['name'])){
echo "Logged in as " . $_SESSION['name'];
}
?>
</div>
<div id="nav">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="film.php">Film</a></li>
<?php
if (isset($_session['user_id']) and isset($_SESSION['name'])) {
echo "<li><a href='review_a_film.php'>Review a film</a></li>";
} ?>
<li><a href="logout.php">logout</a></li>
</ul>
</div>