Are there alternative approaches to verifying user rights in PHP besides using sessions?

Issue: Sessions are a common method for verifying user rights in PHP, but there are alternative approaches such as using JSON Web Tokens (JWT) or implementing custom authentication mechanisms. Alternative approach using JWT:

<?php

// Generate JWT token with user rights
function generateJWT($userId, $userRights) {
    $payload = array(
        "user_id" => $userId,
        "user_rights" => $userRights
    );

    $token = JWT::encode($payload, 'secret_key');
    return $token;
}

// Verify JWT token and check user rights
function verifyJWT($token, $requiredRights) {
    try {
        $decoded = JWT::decode($token, 'secret_key', array('HS256'));
        if (in_array($requiredRights, $decoded->user_rights)) {
            return true;
        }
    } catch (Exception $e) {
        return false;
    }

    return false;
}

// Example usage
$userId = 123;
$userRights = ["admin", "editor"];
$token = generateJWT($userId, $userRights);

if (verifyJWT($token, "admin")) {
    echo "User has admin rights.";
} else {
    echo "User does not have admin rights.";
}
?>