-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
36 lines (31 loc) · 1.02 KB
/
config.php
File metadata and controls
36 lines (31 loc) · 1.02 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
<?php
// Ensure session is started on every page
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Debugging: Check if session variables exist
// Uncomment below lines to debug and check session values
// echo "User ID: " . ($_SESSION['user_id'] ?? 'Not Set') . "<br>";
// echo "User Role: " . ($_SESSION['role'] ?? 'Not Set') . "<br>";
$host = "localhost";
$username = "root";
$password = "";
$database = "pixsoft_db";
// Connect to MySQL
$conn = mysqli_connect($host, $username, $password);
if (!$conn) {
die("Database connection failed: " . mysqli_connect_error());
}
// Select the database
if (!mysqli_select_db($conn, $database)) {
$sql = "CREATE DATABASE IF NOT EXISTS $database";
if (mysqli_query($conn, $sql)) {
mysqli_select_db($conn, $database);
} else {
die("Database creation failed: " . mysqli_error($conn));
}
}
// Ensure session variables are set
$loggedIn = isset($_SESSION['user_id']) && isset($_SESSION['role']);
$userRole = $loggedIn ? $_SESSION['role'] : null;
?>