我有这个公共功能来检查管理员身份验证访问:
class Auth {
public static function checkAdminAuthentication()
{
// initialize the session (if not initialized yet)
Session::init();
// self::checkSessionConcurrency();
// if user is not logged in or is not an admin (= not role type 7)
if (!Session::userIsLoggedIn() || Session::get("user_account_type") != 7) {
// ... then treat user as "not logged in", destroy session, redirect to login page
Session::destroy();
header('location: ' . Config::get('URL') . 'admin/login');
exit();
}
}
和admin控制器类是:
class AdminController extends Controller
{
/**
* Construct this object by extending the basic Controller class
*/
public function __construct()
{
parent::__construct();
// special authentication check for the entire controller: Note the check-ADMIN-authentication!
// All methods inside this controller are only accessible for admins (= users that have role type 7)
Auth::checkAdminAuthentication();
}
/**
* This method controls what happens when you move to /admin or /admin/index in your app.
*/
public function index()
{
$this->Language->load('common/dashboard');
$data['header'] = $this->Language->get('heading_title');
$this->View->render('admin/index','admin', array(
'users' => UserModel::getPublicProfilesOfAllUsers(),
'header' => $this->Language->get('heading_title'),
)
);
}
public function login()
{
$this->Language->load('common/dashboard');
$data['header'] = $this->Language->get('heading_title');
$this->View->render('admin/login','admin', array(
'header' => $this->Language->get('heading_title'),
)
);
}
}
现在我在行动中看到错误并且重定向不完整:
> “Firefox检测到服务器正在以永远不会完成的方式重定向此地址的请求。
有时可能会因禁用或拒绝接受Cookie而导致此问题。“
如何修复此错误?!
答案 0 :(得分:0)
我认为您必须从此检查中排除login()
(将其移至不同的控制器或其他内容),否则它将无限期重定向:
login()
路由之前,__construct
被称为__construct()
重定向到login()
login()
路由之前,__construct
被称为