From 22cf158c58d518a70da311a6ec6a7cb2ff5ca8dd Mon Sep 17 00:00:00 2001 From: Damian Peterson Date: Sat, 26 Aug 2023 07:58:12 +1200 Subject: [PATCH] Redirect after hour change Done to avoid situation where refreshing the page will resubmit the form --- index.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index a8da690..a8b3c46 100644 --- a/index.php +++ b/index.php @@ -52,6 +52,7 @@ $selectedHour = 13; $isLoggedIn = true; $accessToken = $_COOKIE['access_token']; $refreshToken = $_COOKIE['refresh_token']; +$newHour = $_COOKIE['hour']; $customerNumber = ''; $connectionId = ''; $customerName = ''; @@ -231,7 +232,12 @@ if (!isset($accessToken) && !isset($refreshToken)) { try { getCustomerDetails($vars, $accessToken, $customerNumber, $connectionId, $customerName); getCurrentHour($vars, $accessToken, $customerNumber, $connectionId, $selectedHour); - $message = 'Select your hour of power.'; + if ($newHour) { + $message = 'Done, changed to ' . $times[$newHour] . '.'; + setcookie('hour', '', time() - 1000, "/"); + } else { + $message = 'Select your hour of power.'; + } } catch (Exception $exception) { if ($exception->getCode() === 401) { try { @@ -265,7 +271,9 @@ if ($isLoggedIn && $_POST) { if ($isValid) { try { setCurrentHour($vars, $accessToken, $customerNumber, $connectionId, $selectedHour); - $message = 'Done. Hour changed to ' . $times[$selectedHour] . '.'; + setcookie('hour', $selectedHour, time() + 30000, "/"); + header('Location: /'); + die(); } catch (Exception $exception) { $message = $exception->getMessage(); }