-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogout.php
More file actions
31 lines (26 loc) · 880 Bytes
/
Copy pathlogout.php
File metadata and controls
31 lines (26 loc) · 880 Bytes
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
<?php
session_start();
// Database Connection
$conn = new mysqli("localhost", "root", "", "classify_db");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Log function
function log_action($conn, $action) {
$user_role = isset($_SESSION['role']) ? $_SESSION['role'] : 'unknown';
$user_name = isset($_SESSION['fullname']) ? $_SESSION['fullname'] : 'unknown';
$sql = "INSERT INTO activity_logs (user_role, user_name, action, timestamp) VALUES (?, ?, ?, NOW())";
$stmt = $conn->prepare($sql);
if ($stmt) {
$stmt->bind_param("sss", $user_role, $user_name, $action);
$stmt->execute();
$stmt->close();
}
}
// Log the logout action before destroying the session
log_action($conn, "Logged out");
// Destroy session and redirect
session_destroy();
header("Location: classify_login.php");
exit();
?>