commit 54d6a7573c6bea9c5e01ace72e531c5bca4cd14f Author: sawontheboss4 Date: Mon Aug 4 15:37:38 2025 +0600 first commit diff --git a/index.php b/index.php new file mode 100644 index 0000000..972699d --- /dev/null +++ b/index.php @@ -0,0 +1,143 @@ += 2004 && $firstFourDigits <= 2018) { + return ['valid' => $cleanedInput]; + } else { + return ['invalid' => $cleanedInput, 'reason' => 'First four digits are not within 2004-2018']; + } + } else { + return ['invalid' => $cleanedInput, 'reason' => 'Not 17 digits long']; + } +} + +$validResults = []; +$invalidResults = []; +$error = null; + +// Validate the request method and CSRF token +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { + $error = "Invalid CSRF token."; + } else { + $inputData = filter_input(INPUT_POST, 'input_data', FILTER_SANITIZE_STRING); + $rows = explode("\n", trim($inputData)); + + foreach ($rows as $row) { + $result = processInput($row); + if ($result && isset($result['valid'])) { + $validResults[] = $result['valid']; + } elseif ($result) { + $invalidResults[] = $result; + } + } + + // Remove duplicate valid results + $validResults = array_unique($validResults); + } +} + +// Function to create a downloadable file link +function createDownloadLink($filename, $data) { + $filepath = sys_get_temp_dir() . '/' . $filename; + file_put_contents($filepath, implode("\n", $data)); + return $filepath; +} + +// Handle the download of valid results +if (isset($_POST['download_valid']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) { + $filepath = createDownloadLink('valid_results.txt', $validResults); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="valid_results.txt"'); + readfile($filepath); + exit; +} + +// Handle the download of invalid results +if (isset($_POST['download_invalid']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) { + $invalidOutput = array_map(function ($item) { + return $item['invalid'] . " - " . $item['reason']; + }, $invalidResults); + $filepath = createDownloadLink('invalid_results.txt', $invalidOutput); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="invalid_results.txt"'); + readfile($filepath); + exit; +} +?> + + + + + + + Input Validator + + + +
+

Input Validator

+ +
+ +
+
+

+ + +
+ + +
+

Results

+

Input Rows:

+

Valid Output Rows (Unique):

+

Invalid/Discarded Rows:

+ + 0): ?> +

Discarded Inputs:

+
    + +
  • -
  • + +
+ + +
+ + + 0): ?> + + + 0): ?> + + +
+
+ +
+ + diff --git a/index3-old.php b/index3-old.php new file mode 100644 index 0000000..454a766 --- /dev/null +++ b/index3-old.php @@ -0,0 +1,135 @@ += 2004 && $firstFourDigits <= 2018) { + return ['valid' => $cleanedInput]; + } else { + return ['invalid' => $cleanedInput, 'reason' => 'First four digits are not within 2004-2018']; + } + } else { + return ['invalid' => $cleanedInput, 'reason' => 'Not 17 digits long']; + } +} + +$validResults = []; +$invalidResults = []; +$error = null; + +// Validate the request method and CSRF token +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { + $error = "Invalid CSRF token."; + } else { + $inputData = filter_input(INPUT_POST, 'input_data', FILTER_SANITIZE_STRING); + $rows = explode("\n", trim($inputData)); + + foreach ($rows as $row) { + $result = processInput($row); + if (isset($result['valid'])) { + $validResults[] = $result['valid']; + } else { + $invalidResults[] = $result; + } + } + } +} + +// Function to create a downloadable file link +function createDownloadLink($filename, $data) { + $filepath = sys_get_temp_dir() . '/' . $filename; + file_put_contents($filepath, implode("\n", $data)); + return $filepath; +} + +// Handle the download of valid results +if (isset($_POST['download_valid']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) { + $filepath = createDownloadLink('valid_results.txt', $validResults); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="valid_results.txt"'); + readfile($filepath); + exit; +} + +// Handle the download of invalid results +if (isset($_POST['download_invalid']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) { + $invalidOutput = array_map(function ($item) { + return $item['invalid'] . " - " . $item['reason']; + }, $invalidResults); + $filepath = createDownloadLink('invalid_results.txt', $invalidOutput); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="invalid_results.txt"'); + readfile($filepath); + exit; +} +?> + + + + + + + Input Validator + + + +
+

Input Validator

+ +
+ +
+
+

+ + +
+ + +
+

Results

+

Input Rows:

+

Valid Output Rows:

+

Invalid/Discarded Rows:

+ + 0): ?> +

Discarded Inputs:

+
    + +
  • -
  • + +
+ + +
+ + + 0): ?> + + + 0): ?> + + +
+
+ +
+ + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..79a24e9 --- /dev/null +++ b/style.css @@ -0,0 +1,121 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + color: #333; + line-height: 1.6; + padding: 20px; +} + +.container { + max-width: 800px; + margin: auto; + background: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1 { + text-align: center; + color: #333; + margin-bottom: 20px; + font-size: 2.5rem; +} + +label { + font-size: 1.2rem; + margin-bottom: 10px; + display: block; + color: #555; +} + +textarea { + width: 100%; + padding: 10px; + margin-bottom: 20px; + border-radius: 4px; + border: 1px solid #ccc; + font-size: 1rem; + resize: vertical; +} + +.btn { + background-color: #007bff; + color: #fff; + padding: 10px 20px; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 1rem; +} + +.btn:hover { + background-color: #0056b3; +} + +.btn-error { + background-color: #dc3545; +} + +.btn-error:hover { + background-color: #c82333; +} + +.results { + margin-top: 20px; +} + +.results h2 { + margin-bottom: 15px; + color: #333; +} + +.results p { + margin-bottom: 10px; + font-size: 1.1rem; +} + +.error-title { + color: #dc3545; + margin-top: 15px; + font-size: 1.2rem; +} + +.error-list { + list-style: none; + margin-top: 10px; +} + +.error-item { + color: #dc3545; + margin-bottom: 5px; +} + +.download-buttons { + margin-top: 20px; +} + +@media (max-width: 768px) { + .container { + padding: 15px; + } + + h1 { + font-size: 2rem; + } + + .btn, .btn-error { + width: 100%; + margin-bottom: 10px; + } + + .results p { + font-size: 1rem; + } +} \ No newline at end of file