做这样的事情。这会起作用。
<?php
session_start();
if(!empty($_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 } else if(!empty($_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 } ?>
,
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 } ?>
,
session_start()函数需要在php内编写并编写如下代码:
<?php
session_start();
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 } ?>
本文链接:https://www.f2er.com/3022802.html