Source for file Controller.php
Documentation is available at Controller.php
* Controlls access to a group of php access
* and redirects to a predefined login page as
* include_once('Auth.php');
* include_once('Auth/Controller.php');
* $_auth = new Auth('File', 'passwd');
* $authController = new Auth_Controller($_auth, 'login.php', 'index.php');
* $authController->start();
* include_once('Auth.php');
* include_once('Auth/Controller.php');
* $_auth = new Auth('File', 'passwd');
* $authController = new Auth_Controller($_auth, 'login.php', 'index.php');
* $authController->start();
* if( $authController->isAuthorised() ){
* $authController->redirectBack();
/** var Auth An auth instance */
/** var string The login url */
/** var string The default index page, used when login redirects and the caller page in not set or is the login page it's self */
/** var bool If this is set to true auther a succesfull login the Auth_Controller::redirectBack() is invoked automatically */
var $autoRedirectBack = false;
* @param Auth An auth instance
* @param string The login page
* @param string The default page to go to if return page is not set
* @param array Some rules about which urls need to be sent to the login page
* @todo Add a list of urls which need redirection
function Auth_Controller (&$auth_obj, $login= 'login.php', $default= 'index.php', $accessList=array ()) {
$this->auth = & $auth_obj;
$this->_loginPage = $login;
$this->_defaultPage = $default;
if (!empty ($_GET['return']) && $_GET['return'] && !strstr($_GET['return'], $this->_loginPage)) {
#print "Return: {$_GET['return']} <br/>";
$this->auth->setAuthData ('returnUrl', $_GET['return']);
* Enables auto redirection when login is done
* @param bool Sets the autoRedirectBack flag to this
* @see Auth_Controller::autoRedirectBack
function setAutoRedirectBack ($flag = true ){
$this->autoRedirectBack = $flag;
* Redirects Back to the calling page
function redirectBack () {
// If redirectback go there
// else go to the default page
$returnUrl = $this->auth->getAuthData ('returnUrl');
$returnUrl = $this->_defaultPage;
// Add some entropy to the return to make it unique
// avoind problems with cached pages and proxies
if(strpos($returnUrl, '?') === false ) {
header('Location:'. $returnUrl);
print (" You could not be redirected to <a href=\"$returnUrl\">$returnUrl</a>" );
* Redirects to the login Page
* put return page on the query or in auth
function redirectLogin () {
// For Auth, put some check to avoid infinite redirects, this should at least exclude
$url = $this->_loginPage;
if(strpos($url, '?') === false ) {
#print "ServerPhp:".$_SERVER['PHP_SELF'];
if(!strstr($_SERVER['PHP_SELF'], $this->_loginPage)) {
$url .= 'return='. urlencode($_SERVER['PHP_SELF']);
print (" You could not be redirected to <a href=\"$url\">$url</a>" );
* Starts the Auth Procedure
* If the page requires login the user is redirected to the login page
* otherwise the Auth::start is called to initialize Auth
* @todo Implement an access list which specifies which urls/pages need login and which do not
// Check the accessList here
// ACL should be a list of urls with allow/deny
// Some wild card matching should be implemented ?,*
if(!strstr($_SERVER['PHP_SELF'], $this->_loginPage) && !$this->auth->checkAuth ()) {
// Logged on and on login page
if(strstr($_SERVER['PHP_SELF'], $this->_loginPage) && $this->auth->checkAuth ()){
// Should we call this here
// or in the login page manually
$this->autoRedirectBack ?
* Checks is the user is logged on
function isAuthorised () {
return($this->auth->checkAuth ());
return($this->auth->checkAuth ());
return($this->auth->logout ());
* @see Auth::getUsername()
return($this->auth->getUsername ());
return($this->auth->getStatus ());
Documentation generated on Mon, 11 Mar 2019 13:52:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|