/** * Validates the current user's login credentials and redirects to the login form if they do not have access to the requested page. * This function is intended to be called at the top of any pages that require a user be logged in. * * @static * @param string $type Optional user type (part of the table schema) to test against. Use this to validate admin users on admin only pages. * @access public */ static function Validate() { if (!User::LoggedIn()) { $_SESSION['LoginRequest'] = WebPath::Me(); $_SESSION['LoginMessage'] = "You must be logged-in to access that page."; Response::Redirect('/login/'); } elseif (func_num_args()) { if (!User::Current()->isType(func_get_args())) { $page = new pErrorPage("You do not have permission to view this page."); //pErrorPage is a Page template for displaying errormessages. This is a cleaner option to calling die() and stops page execution. } } }
/** * Sends a location header and terminates the controller, redirecting the browser to a new location. * * @param string URL to redirect to. Defaults to the current url if omitted. * @return void **/ public static function Redirect($url = ".") { if ($url == '.') { $url = WebPath::Me(); } header("Location: {$url}"); Database::Disconnect(); exit; }