// * ask for authentication and set if successful // * if not authenticated, display the login form //====================================================== // This code will be loaded into the App Boostrap automatically, to provide the Authentication for the admin.php ... // By default this code does not contain any classes or functions. // If you include classes or functions here they must be called to run here as the app boostrap just include this file at runtime //====================================================== //------------------------------------------- // This file can be customized as you need. //------------------------------------------- // NOTICE: As this is just a sample will use a fixed authentication with: // username = admin // password = pass // This sample can be extended to read the authentication from a database or to use session in combination with SmartAuth. // The best way to integrate with framework's authentication is using the SmartAuth:: object. //------------------------------------------- // v.160219 / Sample Auth based on Basic HTTP Authentication (for Admin Area, overall) if ((string) $_SERVER['PHP_AUTH_USER'] == 'admin' and (string) $_SERVER['PHP_AUTH_PW'] == 'pass') { //-- OK, loggen in SmartAuth::set_login_data((string) $_SERVER['PHP_AUTH_USER'], (string) $_SERVER['PHP_AUTH_USER'], '*****@*****.**', 'Test Admin', array('admin', 'superadmin'), 0, array('title' => 'Mr.', 'name_f' => 'Test', 'name_l' => 'Admin'), 'SMART-FRAMEWORK.TEST', 'HTTP-BASIC', (string) $_SERVER['PHP_AUTH_PW']); //-- } else { //-- NOT OK, display the Login Form and Exit header('WWW-Authenticate: Basic realm="Administration Area"'); http_response_code(401); die(SmartComponents::http_message_401_unauthorized('Authorization Required<br>Login Failed. Either you supplied the wrong credentials or your browser doesn\'t understand how to supply the credentials required.')); //-- } //end if //------------------------------------------- // end of php code
public static final function Raise401Error($y_msg) { //-- if (!headers_sent()) { http_response_code(401); } else { Smart::log_warning('Headers Already Sent before 401 ...'); } //end if else die(SmartComponents::http_message_401_unauthorized(Smart::escape_html((string) $y_msg))); //-- }