I have a problem error :
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in D:\laragon\www\pos\src\session.php on line 6
and I can't find a solution to fix it. Here is my code:
<?php
class Session
{
public function __construct(public string $username, public string $role)
{
}
}
class SessionManager
{
public static string $SECRET_KEY = "xxxxx";
public static function login(string $username, string $password): bool
{
if ($username == "edward" && $password == "edward") {
$payload = [
"username" => $username,
"role" => "customer"
];
$jwt = \Firebase\JWT\JWT::encode($payload, SessionManager::$SECRET_KEY, 'HS256');
setcookie("TRPS-SESSION", $jwt);
return true;
} else {
return false;
}
}
public static function getCurrentSession(): Session
{
if($_COOKIE['TRPS-SESSION']){
$jwt = $_COOKIE['X-PZN-SESSION'];
try {
$payload = \Firebase\JWT\JWT::decode($jwt, SessionManager::$SECRET_KEY, ['HS256']);
return new Session(username: $payload->username, role: $payload->role);
}catch (Exception $exception){
throw new Exception("User is not login");
}
}else{
throw new Exception("User is not login");
}
}
}