我正在尝试管理登录页面,如果仍然记录,则重定向到主页:
$app->get("/",function() use ($app){
if(!isset($_SESSION['group_id'])){
View::login(); // Show login page
}else{
$app->redirect('home/'.$_SESSION['group_id']); // Go to home -> This works!
}
});
$app->get("/home/:group_id",function($group_id) use ($app){
if(isset($_SESSION['group_id'])){
if($_SESSION['group_id'] == $group_id){
View::home();
}else{
$app->redirect('home/'.$_SESSION['group_id']); //-> This doesn't work! It goes to mydomain/home... and not to mydomain/mypath/home...
}
}else{
$app->redirect('/'); // This doesn't work! It goes to the root path of my webserver
}
});
代码中的评论谈论我的问题。有人能帮我吗? :)
答案 0 :(得分:0)
我这样解决了:
$app->get("/",function() use ($app){
if(!isset($_SESSION['group_id'])){
View::login(); // Show login page
}else{
$app->redirect('home/'.$_SESSION['group_id']); // Go to home -> This works!
}
});
$app->get("/home/:group_id",function($group_id) use ($app){
if(isset($_SESSION['group_id'])){
if($_SESSION['group_id'] == $group_id){
View::home();
}else{
$app->redirect('../');
}
}else{
$app->redirect('../');
}
});