require_once 'auth.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = $_POST['username']; $password = $_POST['password']; if (auth_login($username, $password)) { // Redirect to dashboard header('Location: dashboard.php'); exit(); } else { // Show error message $error = 'Invalid username or password'; } } ?>
require_once 'auth.php'; // Check if user is an admin if (!auth_has_role('admin')) { http_response_code(403); die('Access denied'); } // Display admin panel echo 'Welcome, admin!';This example shows how to use the `auth_has_role` function to check if a user has a certain role (in this case, 'admin'). If the user is not an admin, it returns a 403 error and terminates the script. If the user is an admin, it displays a welcome message. In conclusion, PHP Auth Admin is a package library that provides authentication and authorization functionality for PHP web applications. It offers various functions and features that makes it easy to secure your application.