我有两个用户,一个是'admin'和'user'。当我以“用户”的身份登录时,我需要隐藏一些网址。
我的add_sales.php文件包含一些代码
<div class="side-menu fl">
<h3>Sales Management</h3>
<ul>
<?php if($_SESSION['usertype'] == 'admin' ) { ?>
<li><a href="add_sales.php">Add Sales</a></li>
<li><a href="view_sales.php">View Sales</a></li>
<?php } ?>
<?php else if($_SESSION['usertype'] == 'user' ) { ?>
<li><a href="add_sales.php">Add Sales</a></li>
<?php } ?>
</ul>
</div> <!-- end side-menu -->
当我作为'用户'访问时我使用此代码来使用用户if($ _ SESSION [usertype'] =='user')我不知道这是对的错误请一些人帮忙 我.. 我的cheacklog.php是
if($count==1){
$row = mysql_fetch_row($result);
$_SESSION['id']=$row[0];
$_SESSION['username']=$row[1];
$_SESSION['usertype']=$row[3];
if($row[3]=="admin"){
header("location:dashboard.php");
}
else if($row[3]=="user")
{
header("location:dashboard.php");
}
}
?>
答案 0 :(得分:1)
你可以在线编写。仅当用户具有管理员状态时,才会将此链接插入页面:
<ul>
<li><a href="general.php">All users will see this link</a></li>
<?php
if ($row[3]=="admin") {
echo "<li><a href='adminStuff.php'>hidden link</a></a>";
}
?>
</ul>
我很确定这就是你的意思,或者如果你想做有条件的重定向,我想你已经完成了。
答案 1 :(得分:0)
试试这个:
<?php if ($_SESSION['userType'] == 'admin'): ?>
<a>Only admin can see this. </a>
<?php else if($_SESSION['userType'] == 'user' ): ?>
<a>Only user can see this</a>
<?php endif ?>