我有一段代码,我只是写,检测是否有登录和用户,如果[1] [2]有串在任何特定的文本,然后将迁至该人向另一人页面是否符合值。简化PHP如果公司和数组
但我认为我的代码是一个小长篇大论。有什么方法可以简化我拥有的或者我会得到的最好的?
if (!isset($_SESSION['user_id'])){
$dir = dirname($_SERVER['PHP_SELF']);
$dirs = explode('/', $dir);
if(isset($dirs[1])){
if (($dirs[1] == "account") || ($dirs[1] == "admin")){
header('Location: /');
}
}
if(isset($dirs[2])){
if(($dirs[2] == "account")){
header('Location: /');
}
}
}
在此先感谢
也许你可以使用mod_rewrite并为这些路径指定重写规则? –
已修改代码,该代码片段在if语句中以检查用户是否已登录 – ngplayground