Source for file Controller.php
Documentation is available at Controller.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
// $Id: Controller.php,v 1.8 2006/02/28 02:19:22 aashley Exp $
* 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();
* @author Yavor Shahpasov <yavo@netsmart.com.cy>
* @author Adam Ashley <aashley@php.net>
* @version $Revision: 1.8 $
* The Auth instance this controller is managing
* The default index page to use when the caller page is not set
* If this is set to true after a succesfull login the
* Auth_Controller::redirectBack() is invoked automatically
// {{{ Auth_Controller() [constructor]
* @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)) {
if(!empty ($_GET['authstatus']) && $this->auth->status == '') {
// {{{ setAutoRedirectBack()
* Enables auto redirection when login is done
* @param bool Sets the autoRedirectBack flag to this
* @see Auth_Controller::autoRedirectBack
* Redirects Back to the calling page
// If redirectback go there
// else go to the default page
$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 if not authorised
* put return page on the query or in auth
// For Auth, put some check to avoid infinite redirects, this should at least exclude
$url = $this->_loginPage;
if(strpos($url, '?') === false ) {
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
// If allow set allowLogin to false
// Some wild card matching should be implemented ?,*
// Logged on and on login page
* Checks is the user is logged on
* @see Auth::getUsername()
Documentation generated on Mon, 11 Mar 2019 14:37:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|