-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_connect.php
More file actions
31 lines (25 loc) · 802 Bytes
/
db_connect.php
File metadata and controls
31 lines (25 loc) · 802 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();
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "autodata1";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("فشل الاتصال: " . $conn->connect_error);
}
// Debugging: Check if session variables are set
if (!isset($_SESSION['loggedin'])) {
error_log("User not logged in. Redirecting to login page.");
}
// Redirect to login page if not logged in
if (!isset($_SESSION['loggedin']) && basename($_SERVER['PHP_SELF']) != 'login.php') {
header("Location: login.php");
exit();
}
// Restrict access to admin page
if (basename($_SERVER['PHP_SELF']) == 'admin.php' && $_SESSION['role'] != 'admin') {
header("Location: index.php");
exit();
}
?>