<?php session_start(); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'darkmode') { $darkmode = $_POST['value'] === 'true' ? 'true' : 'false'; $_SESSION['darkmode'] = $darkmode; // Update the session to reflect the new mode // Send a JSON response back to JavaScript header('Content-Type: application/json'); echo json_encode(['darkmode' => $darkmode]); exit; }