• checking if a page requires authentication
    0 replies, posted
Now I'm trying a slightly different approach I have the current code: [code] // Ensures the user is required to be logged in on the pageauthenticator. public function checkAuthPage($controller_name = null, $action_name = null, $condition = false) { global $_pageauthenticator; // check to see if the controller name exists within the authenticator. if ( array_key_exists($controller_name, $_pageauthenticator) ) { // Check to see if we're also on the action page - otherwise we're just on the controller. if (array_key_exists('exceptions', $_pageauthenticator[$controller_name])) { // Does the action page require a login? $exceptions = explode(',', $_pageauthenticator[$controller_name]['exceptions']); foreach($exceptions as $k => $v) { $aname = trim($v); if ($action_name == $aname) { return false; } } } else { // Requires login? if($_pageauthenticator[$controller_name]['requires_login']) { if (!$condition) $this->redirectUser(); else return false; } else { return false; } } if (!$condition) $this->redirectUser(); else return false; } } [/code] Which checks against an array like so: [code] $_pageauthenticator = array ( 'main' => array ('requires_login' => true, 'exceptions' => 'login, register'), 'accountSettings' => array ('requires_login' => true, 'exceptions' => ''), 'courseManager' => array ('requires_login' => true, 'exceptions' => ''), 'companyManager' => array ('requires_login' => true, 'exceptions' => '') ); [/code] Now there is nothing crazy about this it's just probably really bad code + the fact I am half asleep at this hour. So, out of curiosity why would only 'main' be working correctly, but not the other pages?
Sorry, you need to Log In to post a reply to this thread.