Handle logging out of the system. The logout link in protected.php leads here. ---------------------------------------------------*/ if (isset($_GET['logout'])) { $user = new User(); if ($user->loggedIn()) { $user->logout(); } redirect('index.php'); } /*-------------------------------------------------- Don't show the login page to already logged-in users. ---------------------------------------------------*/ $user = new User(); if ($user->loggedIn()) { redirect('protected.php'); } /*-------------------------------------------------- Handle submitting the login form via AJAX ---------------------------------------------------*/ try { if (!empty($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { // Output a JSON header header('Content-type: application/json'); // Is the email address valid? if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { throw new Exception('Please enter a valid email.'); } // This will throw an exception if the person is above // the allowed login attempt limits (see functions.php for more):
<?php require_once "../config/settings.php"; $user = new User(); try { $logged_in = $user->loggedIn(); } catch (Exception $e) { echo $e->getMessage(); $logged_in = false; } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Acces zona administrare</title> </head> <body class="page-body">
<html> <head> <title>Vanity</title> <link rel="stylesheet" type="text/css" href="css/styles.css"/> </head> <body> <img src="images/vanity.png"/> <?if (User::loggedIn()){?> Welcome, <?php echo User::getLoggedInUser()->username; ?> (<a href="createpost.php">Create a new post</a>) <?}?>
<?php // To protect any php page on your site, include main.php // and create a new User object. It's that simple! require_once 'includes/main.php'; $user = new User(); if (!$user->loggedIn()) { redirect('index.php'); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Protected page</title> <!-- The main CSS file --> <link href="assets/css/style.css" rel="stylesheet" /> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <div id="protected-page"> <img src="assets/img/lock.jpg" alt="Lock" /> <h1>You are logged in!</h1>
function loggedIn() { return User::loggedIn(); }