= 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): ?>