我不是PHP的专业人士,所以需要一些帮助。
我在我的网站上具有登录功能,该功能可以检查用户是管理员还是普通用户,可以正常运行。
我添加了一项新功能,系统应在该功能中检查用户是否已登录并显示不同的按钮。
但是,它仅对用户有效。我想念什么? UserTypeID
在数据库中为用户设置1,为管理员设置2。
session_start();
<?php
if(isset($_SESSION['UserTypeID']) == 1) //check if user is a user and display buttons
{
?>
<li><a href="user.php">My Account</a></li>
<li><a href="logout.php">Logout</a></li>
<?php } elseif(isset($_SESSION['UserTypeID']) == 2) //check if user is an admin and display buttons
{
?>
<li><a href="admin.php">My Account</a></li>
<li><a href="logout.php">Logout</a></li>
<?php }else{ // if user is not logged in then display these buttons?>
<li><a href="signin.php">Sign In</a></li>
<li><a href="signup.php">Sign Up</a></li>
<?php } ?>
[isset($_SESSION['UserTypeID'])
返回true
或false
session_start();
<?php if(isset($_SESSION['UserTypeID']) && $_SESSION['UserTypeID']== 1) //check if user is a user and display buttons
{
?>
<li><a href="user.php">My Account</a></li>
<li><a href="logout.php">Logout</a></li>
<?php } elseif(isset($_SESSION['UserTypeID']) && $_SESSION['UserTypeID'] == 2) //check if user is an admin and display buttons
{
?>
<li><a href="admin.php">My Account</a></li>
<li><a href="logout.php">Logout</a></li>
<?php }else{ // if user is not logged in then display these buttons?>
<li><a href="signin.php">Sign In</a></li>
<li><a href="signup.php">Sign Up</a></li>
<?php } ?>