true, 'message' => $errorMessage, ]; // Set the content type to JSON header('Content-Type: application/json'); // Output the JSON response echo json_encode($response); exit(); } else { // If no error message is provided, redirect to a generic error page or home page header("Location: /"); // You can change this to the appropriate URL exit(); } ?>