From 9357f90aae58b351819393f4265806ec8d9314da Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 31 Jan 2022 16:08:43 +0100 Subject: [PATCH] Improved http status code in error case. --- index.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index b27cd7a..ee68ef1 100755 --- a/index.php +++ b/index.php @@ -41,33 +41,50 @@ if ( if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) $params['txt'] = $_POST['txt']; else + { + http_response_code(400); exit("Wrong value for txt"); + } if ($_POST['redondancy'] === "L" OR $_POST['redondancy'] === "M" OR $_POST['redondancy'] === "Q" OR $_POST['redondancy'] === "H") $params['redondancy'] = $_POST['redondancy']; else + { + http_response_code(400); exit("Wrong value for redondancy"); + } if (is_numeric($_POST['margin']) AND $_POST['margin'] >= 0 AND $_POST['margin'] <= 128) $params['margin'] = $_POST['margin']; else + { + http_response_code(400); exit("Wrong value for margin"); + } if (is_numeric($_POST['size']) AND $_POST['size'] >= 1 AND $_POST['size'] <= 128) $params['size'] = $_POST['size']; else + { + http_response_code(400); exit("Wrong value for size"); + } if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor'])) $params['bgColor'] = $_POST['bgColor']; else + { + http_response_code(400); exit("Wrong value for bgColor"); + } if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['mainColor'])) $params['mainColor'] = $_POST['mainColor']; else + { + http_response_code(400); exit("Wrong value for mainColor"); - + } } ?>