我的开关案例将每个用户重定向到第一个案例,出了什么问题? 我希望'总统'将重定向到admin.php
<?php require "header.php"; ?>
<?php
if ( ! isset($_SESSION['email']) ) {
$msg = urlencode('U dient ingelogd te zijn om op deze pagina te kunnen komen.');
header('location: login.php?msg=' . $msg);
die();
}
$role = $_SESSION['jobTitle'];
switch($role) {
case 'Finance' AND 'VP Finance':
header('location: finance.php');
break;
case 'VP Sales' AND 'Sales Manager (NA)' AND 'Sales Rep':
header('location: sales.php');
break;
case 'President':
header('location: admin.php');
break;
default:
session_destroy();
header('location: login.php');
}
?>
</div>
</body>
</html>
答案 0 :(得分:2)
AND语句不能在切换案例中使用...请尝试以下方法来实现相同的目的:
switch($role) {
case 'Finance':
case 'VP Finance':
header('location: finance.php');
break;
case 'VP Sales':
case 'Sales Manager (NA)':
case 'Sales Rep':
header('location: sales.php');
break;
case 'President':
header('location: admin.php');
break;
default:
session_destroy();
header('location: login.php');
}
答案 1 :(得分:0)
你可以改写
switch($role) {
case 'Finance':
case 'VP Finance':
header('location: finance.php');
break;
case 'VP Sales':
case 'Sales Manager (NA)':
case 'Sales Rep':
header('location: sales.php');
break;
case 'President':
header('location: admin.php');
break;
default:
session_destroy();
header('location: login.php');
}
或者你可以写一些更复杂的表达式内容。
switch(true) {
case ($role == 'Finance' OR $role == 'VP Finance'):
header('location: finance.php');
break;
case ($role =='VP Sales' OR $role =='Sales Manager (NA)' OR $role =='Sales Rep'):
header('location: sales.php');
break;
case $role == 'President':
header('location: admin.php');
break;
default:
session_destroy();
header('location: login.php');
}