-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_session.php
More file actions
120 lines (108 loc) · 5.41 KB
/
check_session.php
File metadata and controls
120 lines (108 loc) · 5.41 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
// check_session.php - Session Diagnostic Tool
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Session Check - DS Diamonds</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 p-8">
<div class="max-w-4xl mx-auto bg-white rounded-lg shadow-lg p-8">
<h1 class="text-3xl font-bold text-gray-800 mb-6">Session Diagnostic</h1>
<div class="mb-6">
<h2 class="text-xl font-semibold mb-3 text-purple-600">Current Session Data:</h2>
<div class="bg-gray-50 p-4 rounded border">
<pre class="text-sm"><?php print_r($_SESSION); ?></pre>
</div>
</div>
<div class="mb-6">
<h2 class="text-xl font-semibold mb-3 text-purple-600">Key Checks:</h2>
<div class="space-y-2">
<div class="flex items-center">
<span class="font-semibold mr-2">Logged In:</span>
<?php if (isset($_SESSION['loggedin']) && $_SESSION['loggedin']): ?>
<span class="bg-green-100 text-green-700 px-3 py-1 rounded-full text-sm">✓ Yes</span>
<?php else: ?>
<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-sm">✗ No</span>
<?php endif; ?>
</div>
<div class="flex items-center">
<span class="font-semibold mr-2">Role:</span>
<?php if (isset($_SESSION['role'])): ?>
<span class="bg-blue-100 text-blue-700 px-3 py-1 rounded-full text-sm font-mono">
<?php echo htmlspecialchars($_SESSION['role']); ?>
</span>
<?php else: ?>
<span class="bg-yellow-100 text-yellow-700 px-3 py-1 rounded-full text-sm">Not Set</span>
<?php endif; ?>
</div>
<div class="flex items-center">
<span class="font-semibold mr-2">User ID:</span>
<span class="text-gray-700">
<?php echo isset($_SESSION['userid']) ? htmlspecialchars($_SESSION['userid']) : 'Not Set'; ?>
</span>
</div>
<div class="flex items-center">
<span class="font-semibold mr-2">User Name:</span>
<span class="text-gray-700">
<?php echo isset($_SESSION['name']) ? htmlspecialchars($_SESSION['name']) : 'Not Set'; ?>
</span>
</div>
</div>
</div>
<?php
// Check if user has role in database
require_once 'config.php';
if (isset($_SESSION['userid'])) {
$user_id = $_SESSION['userid'];
$result = $conn->query("SELECT id, user_id, name, status, role FROM staff WHERE id = $user_id");
if ($result && $result->num_rows > 0) {
$user = $result->fetch_assoc();
?>
<div class="mb-6">
<h2 class="text-xl font-semibold mb-3 text-purple-600">Database User Record:</h2>
<div class="bg-gray-50 p-4 rounded border">
<pre class="text-sm"><?php print_r($user); ?></pre>
</div>
<?php if (!isset($user['role'])): ?>
<div class="mt-4 bg-red-50 border border-red-200 rounded p-4">
<p class="text-red-800 font-semibold mb-2">⚠️ Role Column Missing!</p>
<p class="text-sm text-red-700">The 'role' column doesn't exist in your database. You need to run
migrations.</p>
<a href="run_migrations.php"
class="inline-block mt-3 bg-red-600 text-white px-4 py-2 rounded hover:bg-red-700">
Run Migrations Now
</a>
</div>
<?php elseif (empty($user['role']) || $user['role'] === null): ?>
<div class="mt-4 bg-yellow-50 border border-yellow-200 rounded p-4">
<p class="text-yellow-800 font-semibold mb-2">⚠️ Role Not Set!</p>
<p class="text-sm text-yellow-700">Your user record exists but role is empty. Run this SQL:</p>
<code class="block bg-gray-900 text-green-400 p-3 rounded mt-2 text-xs">
UPDATE staff SET role = 'admin' WHERE id = <?php echo $user['id']; ?>;
</code>
</div>
<?php endif; ?>
</div>
<?php
}
}
?>
<div class="flex gap-4">
<a href="index.php" class="bg-purple-600 text-white px-6 py-2 rounded-lg hover:bg-purple-700">
Back to Login
</a>
<a href="admin_dashboard.php" class="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700">
Try Admin Dashboard
</a>
<a href="logout.php" class="bg-red-600 text-white px-6 py-2 rounded-lg hover:bg-red-700">
Logout
</a>
</div>
</div>
</body>
</html>