Documentation

check_auth.php

Table of Contents

Functions

check_cookies()  : bool
Checks for the existence of authentication cookies.
check_user_cred()  : bool
Validates the user credentials against the database.
check_auth_user()  : bool|void
Enforces that a user is currently logged in.
check_auth_admin()  : bool|void
Enforces that the current user has administrator privileges.

Functions

check_cookies()

Checks for the existence of authentication cookies.

check_cookies() : bool

Verifies if the 'username' and 'user_id' cookies are set in the current request.

Return values
bool

True if both cookies exist, false otherwise.

check_user_cred()

Validates the user credentials against the database.

check_user_cred(string $username, int|string $user_id) : bool

This function uses the User class to verify that the provided username matches the provided user ID in the system records.

Parameters
$username : string

The username to verify.

$user_id : int|string

The user ID to verify.

Tags
throws
Exception

If the database query fails.

Return values
bool

True if the combination is valid, false otherwise.

check_auth_user()

Enforces that a user is currently logged in.

check_auth_user() : bool|void

This function checks for valid cookies and verifies the credentials. If authentication fails, the user is immediately redirected to the login page and script execution is terminated.

Return values
bool|void

Returns true if authenticated; otherwise redirects and exits.

check_auth_admin()

Enforces that the current user has administrator privileges.

check_auth_admin() : bool|void

First ensures the user is logged in via check_auth_user(). Then retrieves the user profile to check the admin status. If the user is not an admin, they are redirected to the home page.

Return values
bool|void

Returns true if the user is an admin; otherwise redirects and exits.


        
On this page

Search results