is_logged_in()

public function is_logged_in(?int $user_level_id = null): string|bool

Description

Checks whether the current user has a valid authentication token. Optionally filters by a specific user level. Useful for conditional logic in controllers where you need to check authentication status without triggering a redirect.

Parameters

ParameterTypeDescriptionDefaultRequired
user_level_idint|nullOptional user level ID to check against. If null, any valid token is accepted.nullNo

Return Value

TypeDescription
string|boolReturns the token string if a valid token is found, or false if not authenticated.

Example Usage

PHP
<?php
if ($this->login->is_logged_in()) {
    echo 'User is logged in';
}

if ($this->login->is_logged_in(1)) {
    echo 'Admin is logged in';
}