$value) {
if ($key !== 'submit') {
$data_to_save[$key] = $value;
}
}
$data_to_save['device_id'] = trim(file_get_contents('/sys/class/dmi/id/product_uuid'));
// Save if no errors occurred
if (empty($errors)) {
if (file_put_contents($json_file, json_encode($data_to_save, JSON_PRETTY_PRINT)) === false) {
$errors[] = "Failed to write to file. Check permissions.";
}
}
if (!empty($errors)) {
$error_message = implode("
", $errors);
} else {
// Redirect to prevent form resubmission on refresh
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
}
// --- 2. Load Data for Display ---
$saved_data = [];
if (file_exists($json_file)) {
$json_content = file_get_contents($json_file);
$saved_data = json_decode($json_content, true) ?? [];
}
function getValue($data, $key)
{
return $data[$key] ?? '';
}
include 'header.php';
?>