Location: PHPKode > projects > Dev's CMS > devscms/includes/class.auth.php
<?php

class auth
{
	private static $_instance;
	public $loginPage;
	public $redirectPage;
	public $password;

	private function __construct($password, $loginPage, $redirectPage)
	{
		$this->password = $password;
		$this->loginPage = $loginPage;
		$this->redirectPage = $redirectPage;
	}

	private function __clone() {}

	public function login($password)
	{
		if ($password == $this->password) {
			$_SESSION['auth']['loggedIn'] = true;
			header ("Location: " . $this->redirectPage);
			die;
		} else {
			header ("Location: " . $this->loginPage . '&failed');
			die;
		}
	}

	public function isLoggedIn()
	{
		return isset($_SESSION['auth']['loggedIn']) && $_SESSION['auth']['loggedIn'];
	}

	public function isLoginPage()
	{
		return substr($this->_getRequestUriIISCompatible(), 0, strlen($this->loginPage)) == $this->loginPage;
	}

	/**
	* @return auth
	*/
	public static function &getInstance()
	{
		if (!isset(self::$_instance)) {
			self::$_instance = new auth(config::get('auth', 'password'), config::get('auth', 'loginPage'), config::get('auth', 'redirectPage'));
		}

		return self::$_instance;
	}

	public function requireLogin()
	{
		if (!$this->isLoggedIn() && !$this->isLoginPage()) {
			$this->redirectToLogin();
		}
	}

	public function redirectToLogin()
	{
		header ("Location: " . $this->loginPage);
		die;
	}

	private function _getRequestUriIISCompatible()
	{
		return str_replace('/index.php', '', $_SERVER['REQUEST_URI']);
	}
}
Return current item: Dev's CMS