Blank dashboard page on multi user login form for 3 users but when a user login on the live server the dashboard page goes blank even though the url is showing that the user is logged in but the page will be total white blank page. Everything is working fine in the local server but having this issue on the live server
here is the dashboard page
home.php
<?php
session_start();
include 'config.php';`
if (!isset($_SESSION['username']) || !isset($_SESSION['id']) || $_SESSION['subscribed'] === false) {
header("Location: unsubscribed.php");
exit();
}
// Fetch unread notification count
$customer_id = $_SESSION['id'];
$stmt = $conn->prepare("SELECT COUNT(*) AS unread_count FROM customer_notifications WHERE customer_id = ? AND is_read = 0");
$stmt->bind_param("i", $customer_id);
$stmt->execute();
$stmt->bind_result($unread_count);
$stmt->fetch();
$stmt->close();
if (!isset($unread_count)) {
$unread_count = 0;
}
?>
footer.php
<script>
document.addEventListener("DOMContentLoaded", function() {
var notificationDropdown = document.getElementById('notificationDropdown');
if (notificationDropdown) {
notificationDropdown.addEventListener('click', function() {
// AJAX call to fetch notifications
var xhr = new XMLHttpRequest();
xhr.open('POST', 'fetch_notifications.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (this.status == 200) {
document.getElementById('notificationsList').innerHTML = this.responseText;
}
};
xhr.send();
// AJAX call to mark notifications as read
var xhrRead = new XMLHttpRequest();
xhrRead.open('POST', 'mark_notifications_read.php', true);
xhrRead.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhrRead.send();
// Optionally, update the UI by hiding the badge
var notificationBadge = document.getElementById('notificationBadge');
if (notificationBadge) {
notificationBadge.style.display = 'none';
}
});
}
});
</script>
login.php is the user login page
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
include "./config.php";
date_default_timezone_set('Africa/Lagos'); // Set PHP timezone to Nigeria
$conn->query("SET time_zone = '+01:00'"); // Set MySQL timezone to Nigeria
$msg = "";
$error = "";
if (isset($_POST['login-btn'])) {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = $_POST['password'];
$usertype = mysqli_real_escape_string($conn, $_POST['usertype']);
if (!empty($username) && !empty($password) && !empty($usertype) && $usertype !== "Select User") {
$sql = "SELECT * FROM users WHERE username=? AND usertype=? LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $username, $usertype);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($result->num_rows == 1 && password_verify($password, $row['password'])) {
if ($row['unsubscribed'] == 1) {
header("Location: de-activated.php");
exit();
}
session_regenerate_id();
$_SESSION['id'] = $row['uid'];
$_SESSION['username'] = $row['username'];
$_SESSION['photo'] = $row['photo'];
$_SESSION['role'] = $row['usertype'];
$_SESSION['subscription_end'] = $row['subscription_end'];
// Update last_login timestamp
$lastLogin = date('Y-m-d H:i:s');
$updateLoginSql = "UPDATE users SET last_login = ? WHERE uid = ?";
$updateLoginStmt = $conn->prepare($updateLoginSql);
$updateLoginStmt->bind_param("si", $lastLogin, $row['uid']);
$updateLoginStmt->execute();
// Store last_login in session
$_SESSION['last_login'] = $lastLogin;
// Check if the user has a valid subscription
$current_date = new DateTime();
$subscription_end = null;
$subscription_status = 'unsubscribed';
$_SESSION['subscribed'] = false;
if ($row['subscription_end'] !== null) {
$subscription_end = new DateTime($row['subscription_end']);
}
if (!empty($row['subscription_type']) && !empty($row['subscription_start']) && $subscription_end !== null && $subscription_end >= $current_date) {
$subscription_status = 'subscribed';
$_SESSION['subscribed'] = true;
}
// Update the subscription status in the database
$update_sql = "UPDATE users SET subscription_status=? WHERE uid=?";
$update_stmt = $conn->prepare($update_sql);
$update_stmt->bind_param("si", $subscription_status, $_SESSION['id']);
$update_stmt->execute();
// Redirect based on subscription status
if ($_SESSION['subscribed'] === false) {
if ($_SESSION['role'] == "Customer") {
header("Location: customer/unsubscribed.php");
} elseif ($_SESSION['role'] == "Mechanic") {
header("Location: mechanic/unsubscribed.php");
} elseif ($_SESSION['role'] == "Partseller") {
header("Location: partseller/unsubscribed.php");
}
exit();
} else {
if ($_SESSION['role'] == "Customer") {
header("Location: customer/home.php");
} elseif ($_SESSION['role'] == "Mechanic") {
header("Location: mechanic/home.php");
} elseif ($_SESSION['role'] == "Partseller") {
header("Location: partseller/home.php");
}
exit();
}
} else {
echo "Username or Password is incorrect";
}
} else {
echo "Please fill all forms correctly";
}
}
?>
Here is the connection file
config.php
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// Define server variables
$servername = "localhost:";
$username = "myusername";
$password = "mypassword";
$dbname = "mydatabase";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
//Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
i don’t really know where error is coming from, please can someone help me out.
6