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
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| user_level_id | int|null | Optional user level ID to check against. If null, any valid token is accepted. | null | No |
Return Value
| Type | Description |
|---|---|
| string|bool | Returns 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';
}