<?php
session_start();
include "connection.php";
if(empty($_SESSION['role']) && $_SESSION['role'] == '0')
{
echo "<p><a href='view.php' class='btn btn-info' role='button'>Admin
button</a></p>";
}
?>
这是我的按钮代码↑
它只能隐藏用户的按钮,并且会向非注册用户显示错误,我该怎么办?
PS:0表示admin,1表示用户
答案 0 :(得分:-1)
试试这个
<?php
session_start();
include "connection.php";
if(
isset($_SESSION['role'])
&& ($_SESSION['role'] == '0' || $_SESSION['role'] == '1')
{
echo "<p><a href='view.php' class='btn btn-info' role='button'>Admin
button</a></p>";
}
?>
答案 1 :(得分:-1)
使用isset而不是空。
<?php
session_start();
include "connection.php";
if(isset($_SESSION['role']) && $_SESSION['role'] == '0')
{
echo "<p><a href='view.php'
class='btn btn-info' role='button'>Admin
button</a></p>";
}
?>