Application Error"; echo "

Error [$errno]: $errstr

"; echo "

Location: $errfile:$errline

"; } else { // Include our styled 500 error page include $_SERVER['DOCUMENT_ROOT'] . '/../app/views/errors/500.php'; } exit(1); } // Return false to let PHP handle non-fatal errors normally return false; } // Set up custom exception handler function customExceptionHandler($exception) { // Log the exception for administrators error_log("Uncaught Exception: " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine()); http_response_code(500); // Only show detailed errors if debug mode is enabled if (isDebugEnabled()) { echo "

Application Exception

"; echo "

Error: " . htmlspecialchars($exception->getMessage()) . "

"; echo "
" . htmlspecialchars($exception->getTraceAsString()) . "
"; } else { // Include our styled 500 error page include $_SERVER['DOCUMENT_ROOT'] . '/../app/views/errors/500.php'; } exit(1); } // Register the custom error and exception handlers set_error_handler('customErrorHandler'); set_exception_handler('customExceptionHandler'); // Set error handling based on debug setting if (isDebugEnabled()) { // Debug mode enabled - show all errors error_reporting(E_ALL); ini_set('display_errors', 1); } else { // Debug mode disabled - hide errors but still log them error_reporting(E_ALL); ini_set('display_errors', 0); ini_set('log_errors', 1); } // Start session session_start(); $dbConnection = null; // Initialize to null try { // Add logging for request method and path $method = $_SERVER['REQUEST_METHOD']; $path = $_SERVER['REQUEST_URI']; error_log("Request: $method $path"); // Check if it's a password request and it's a POST if ($path == "/password/request" && $method == "POST") { error_log("Detected POST to /password/request, POST data: " . print_r($_POST, true)); } // Add logging to check if .env is loaded $envLoaded = false; $envPath = __DIR__ . '/../.env'; // Log environment check error_log("Checking .env file at: $envPath"); if (file_exists($envPath)) { error_log(".env file exists, checking variables"); $envLoaded = getenv('APP_ENV') !== false; error_log("APP_ENV loaded: " . ($envLoaded ? "Yes - " . getenv('APP_ENV') : "No")); } else { error_log(".env file not found at $envPath"); } // Establish database connection $dbConnection = DatabaseHandler::getConnection(); // Load and execute routing file $routingFile = $_SERVER['DOCUMENT_ROOT'] . '/../app/routes/web.php'; error_log("Including routing file: $routingFile"); require_once $routingFile; } catch (Exception $e) { // This will be handled by the custom exception handler throw $e; } finally { // Always close the database connection if ($dbConnection !== null) { DatabaseHandler::closeConnection(); } }