SessionService.php
1 <?php 2 3 namespace ButA2SaeS3\services; 4 5 use ButA2SaeS3\FageDB; 6 use ButA2SaeS3\utils\HttpUtils; 7 8 class SessionService 9 { 10 public static function create_session(FageDB $db, $username) 11 { 12 $session_id = random_bytes(32); 13 $expiration_date = time() + 24 * 60 * 60; 14 setcookie("session", $session_id, expires_or_options: $expiration_date, path: "/", domain: "", secure: true, httponly: true); 15 $db->create_session($username, $session_id, date("Y-m-d H:i:s", $expiration_date)); 16 } 17 18 public static function logout() 19 { 20 self::clear_session(); 21 } 22 23 public static function clear_session() 24 { 25 setcookie( 26 "session", 27 HttpUtils::get_current_user_id(new FageDB()), 28 expires_or_options: 0, 29 path: "/", 30 domain: "", 31 secure: true, 32 httponly: true, 33 ); 34 } 35 }