session_start(); if ($_SESSION['auth'] == true) { // user is authenticated, allow access } else { // user is not authenticated, deny access }
$acl = array( 'admin' => array('dashboard', 'user_management'), 'editor' => array('dashboard'), 'user' => array('profile', 'settings') ); $user = 'editor'; $page = 'dashboard'; if (array_key_exists($user, $acl) && in_array($page, $acl[$user])) { // user is authorized, allow access } else { // user is not authorized, deny access }
// process login form if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; // verify username and password if ($username == 'admin' && $password == 'password') { // user is authenticated, redirect to dashboard header('Location: /dashboard.php'); exit; } else { // user is not authenticated, display error message $error = 'Invalid username or password'; } } // display login form if (!isset($_SESSION['auth'])) { echo ''; } In this example, a login form is displayed to the user, which prompts them to enter their username and password. When the form is submitted, the credentials are verified against a database, file or any other authentication provider, and a session is started if the credentials are valid. If the user is not authenticated, an error message is displayed. Package/Library: Laravel Authentication Mechanism.