-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogout.php
More file actions
54 lines (47 loc) · 1.6 KB
/
Copy pathlogout.php
File metadata and controls
54 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* ==========================================================
* File: logout.php
*
* Description:
* - Handles user logout for Code Gaming platform
* - Features:
* • Logs logout action to login_logs table (user, role, IP, session)
* • Uses Auth class for secure session termination
* • Redirects user to anchor page after logout
*
* Usage:
* - Called when a user chooses to log out
* - Ensures session is properly cleared and activity is logged
*
* Author: [Santiago]
* Last Updated: [July 22, 2025]
* -- Code Gaming Team --
* ==========================================================
*/
require_once 'includes/Auth.php';
require_once 'includes/ActivityLogger.php';
$auth = Auth::getInstance();
// Log the logout action before clearing session
if ($auth->isLoggedIn()) {
$userId = $_SESSION['user_id'] ?? null;
$username = $_SESSION['username'] ?? 'Unknown';
$role = $_SESSION['role'] ?? 'visitor';
// Log logout activity
$logger = ActivityLogger::getInstance();
$isAdmin = ($role === 'admin' || $role === 'super_admin');
$logger->logActivity([
'user_id' => $isAdmin ? null : $userId,
'admin_id' => $isAdmin ? $userId : null,
'username' => $username,
'user_type' => $isAdmin ? 'admin' : 'user',
'action' => 'logged_out',
'action_details' => 'User logged out',
'status' => 'success'
]);
}
// Use the Auth class to handle logout properly
$auth->logout();
// Redirect to anchor page
header('Location: anchor.php');
exit;