我使用以下代码检查登录级别 - 创建必须具有特定访问级别的页面的最优雅方法是什么?
function check_login($level) {
$username_s = mysql_real_escape_string($_SESSION['username']);
$sql = "SELECT user_level, restricted FROM login_users WHERE username = '$username_s'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$user_level = $row['user_level'];
$restricted = $row['restricted'];
$sql = "SELECT level_disabled FROM login_levels WHERE level_level = '$user_level'";
$result = mysql_query($sql);
$row2 = mysql_fetch_array($result);
$disabled = $row['level_disabled'];
if($disabled != 0) { include('disabled.php'); exit();
} elseif($restricted != 0) { include('disabled.php'); exit();
} elseif($user_level <= $level) { // User has authority to view this page.
} else { include('user_level.php'); exit();
}
}