我想转到主页作为当前登录用户的权限.当我尝试打开具有链接的页面时,它将转到主页.我需要对代码进行哪些更改
<body>
<a href="<?php home(); ?> ">Home</a>
</body
function home()
{
if($_SESSION['privillage']=="ADMIN")
{
header('location:admin_home.php');
}
elseif($_SESSION['privillage']=='SUPERVISOR')
{
header('location:home.php');
}
else
{
header('location:user_home.php');
}
}
Run Code Online (Sandbox Code Playgroud)
你的函数是在一个内部使用的<a href="...">,所以它显然应该是return一个URL(你也需要echo它)
您当前的代码正在尝试立即重定向用户,这不会起作用,因为您已经发送过<a href=".
尝试:
function home() {
if($_SESSION['privillage'] == "ADMIN") return "admin_home.php";
if($_SESSION['privillage'] == "SUPERVISOR") return "home.php";
return "user_home.php";
}
Run Code Online (Sandbox Code Playgroud)