<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> <link rel="stylesheet" href="<?php echo $path->getAssetPath(); ?> /css/notes.css"/> </head> <body> <header class="header"> <?php // ================================================================================================================ // LOGIN if (isset($_POST['username']) && isset($_POST['password'])) { // try to log in. if ($authHandler->loginUser($_POST['username'], $_POST['password'])) { echo "<div class='notification success'>Hi " . $authHandler->getUserName() . ", you are now logged in!</div>"; } else { echo "<div class='notification error'>We're sorry, but the log in failed. Is the password correct?</div>"; } } // LOGOUT if (isset($_POST['logout'])) { $authHandler->logoutUser(); } // ================================================================================================================ ?> <div class="brand">Notes</div> <?php if ($authHandler->isUserLoggedIn()) { ?>
<?php error_reporting(E_ALL); // AuthHandler Testclass $DOC_ROOT = $_SERVER['DOCUMENT_ROOT']; $USER_DIR = '/martin'; $PROJECT_NAME = '/hem'; $APP_ROOT = $DOC_ROOT . $USER_DIR . $PROJECT_NAME; $PEAR_DIR = $APP_ROOT . '/pear'; $APP_FRAMEWORK_DIR = $APP_ROOT . '/framework'; $PATH = $PEAR_DIR . ":" . $APP_FRAMEWORK_DIR; ini_set('include_path', ':' . $PATH . ':' . ini_get('include_path')); $DB_URL = 'mysql://*****:*****@localhost/testlu'; require_once 'class.AuthHandler.php'; $auth_handler = new AuthHandler(array('auth_dsn' => $DB_URL, 'auth_session_name' => 'PHPSESSION', 'auth_exit_page' => $_SERVER['SCRIPT_NAME'])); if ($auth_handler->isAuthenticated()) { echo "You're in: " . $auth_handler->getUserName() . "<br/>"; $_SESSION['SESSION_USERNAME'] = $auth_handler->getUserName(); echo "<a href=\"" . $_SERVER['SCRIPT_NAME'] . "?logout=1\">Logout</a>"; } else { echo "<form name='loginForm' action='" . $_SERVER['SCRIPT_NAME'] . "' method=\"post\">"; echo "Username:<input type=\"text\" name=\"handle\" value=\"\" /><br/>"; echo "Password:<input type=\"password\" name=\"passwd\" /><br/>"; echo "Remember me <input type=\"checkbox\" name=\"rememberMe\" /><br/>"; echo "<input type=\"submit\" value=\"Log-in\" />"; echo "</form>"; }