要查看我网站的新闻部分,您必须登录(作为普通帐户 = login_user 或 admin = admin ),您可以按时间顺序查看上传的新闻。如果您未在任何一种情况下登录,请转到其他地方。然而,代码认为即使使用普通帐户或管理员帐户登录并简单地将我定向到其他地方,也不满足任何条件...
<?php
error_reporting(0);
session_start();
if(!isset($_SESSION['admin']) || !isset($_SESSION['login_user']))
{
?>
<div class = "api" style="position: absolute;
top: 140px;
right: 400px;
width: 730px;
height: 400px;word-wrap: break-word;">
<h2 align = "center"> <font color ="red"> You Do Not Have Permission To View this Page. </font> <br><br> Your Options Are:
<br><br><br>
<a href="index.php"> Create and Register for A New Account </a> <br> <br> <br> OR <br> <br> <br> <a href="indexmember.php">Log In With An Existing Account. </h2>
</div>
<?php
}
elseif(isset($_SESSION['admin']) || isset($_SESSION['login_user']))
{
include 'connect.php';
?>
<div class = "api" style="position: absolute;
top: 10px;
right: 220px;
width: 1200px;
height: 3200px;word-wrap: break-word;" id="easyPaginate">
<?php
$query = mysqli_query($con,"select * from news order by date DESC");
while($r = mysqli_fetch_array($query))
{
?>
<section class="propertypage">
<br> <br>
<h4><?php echo "<b><u>Title</u>: </b>".$r['Title']; ?></h4>
<h4><?php echo "<b><u>Detail</u>: </b>".$r['story']; ?></h4>
<h4><?php echo "<b><u>Published Date</u>: </b>".$r['DATE']; ?></h4>
<img src="<?php echo $r['image']; ?>" height="600px" width="1200px"/>
<br> <br> <br>
</section>
<?php
}
?>
</div>
<?php
}
?>
最佳答案
你想要:
if(!isset($_SESSION['admin']) && !isset($_SESSION['login_user']))
// ....
这就是说,如果用户不是管理员并且用户不是登录用户,那么他们一定没有权限。
关于PHP - IF 语句普通用户或管理员有权访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37954733/