我正在尝试为我网站上的每个页面创建会话变量检查。下面的代码很接近,但我只是不知道我是否正确构造了 If、elseif 和 else 语句。谢谢!
<?php
session_start();
if (isset($_SESSION['id']) && $_SESSION['administrator'] == 'YES'){
session_write_close();
echo "You are logged in & you are an administrator!";
exit();
} elseif (isset($_SESSION['id'])){
session_write_close();
echo "You are logged in BUT you are NOT an administrator!";
exit();
} else {
session_write_close();
echo "You are NOT logged in!";
exit();
}
?>