在php用户身份验证中重定向请求未完成
我有一个用于检查管理员身份验证访问的公共功能:在php用户身份验证中重定向请求未完成,php,Php,我有一个用于检查管理员身份验证访问的公共功能: 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
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();
}
}
管理控制器类为:
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造成的。”
如何修复此错误 我认为您必须从该检查中排除
login()
(通过将其移动到其他控制器或其他地方),否则它将无限期重定向:
- 在调用
路由之前,调用login()
\u构造
重定向到\uu construct()
登录()
- 在调用
路由之前,调用login()
\u构造
- 等等