first commit

This commit is contained in:
sawontheboss4 2025-08-04 15:37:38 +06:00
commit 54d6a7573c
3 changed files with 399 additions and 0 deletions

143
index.php Normal file
View File

@ -0,0 +1,143 @@
<?php
// Set headers to prevent search engines from indexing the page
header("X-Robots-Tag: noindex, nofollow", true);
// Start session for CSRF token
session_start();
// Generate a CSRF token if one isn't set
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
// Function to process input data
function processInput($input) {
// Ignore blank lines
if (trim($input) === '') {
return null;
}
// Step 1: Remove any non-numeric characters
$cleanedInput = preg_replace('/\D+/', '', $input);
// Step 2: Filter only 17 digits long strings
if (preg_match('/^\d{17}$/', $cleanedInput)) {
// Step 3: Check if the first four digits are within 2004-2018
$firstFourDigits = substr($cleanedInput, 0, 4);
if ($firstFourDigits >= 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;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow">
<title>Input Validator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Input Validator</h1>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post">
<label for="input_data">Enter your data (one per line):</label><br>
<textarea id="input_data" name="input_data" rows="10" cols="50"><?= isset($_POST['input_data']) ? htmlspecialchars($_POST['input_data']) : '' ?></textarea><br><br>
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<button type="submit" class="btn">Process</button>
</form>
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error): ?>
<div class="results">
<h2>Results</h2>
<p>Input Rows: <strong><?= count($rows) ?></strong></p>
<p>Valid Output Rows (Unique): <strong><?= count($validResults) ?></strong></p>
<p>Invalid/Discarded Rows: <strong><?= count($invalidResults) ?></strong></p>
<?php if (count($invalidResults) > 0): ?>
<h3 class="error-title">Discarded Inputs:</h3>
<ul class="error-list">
<?php foreach ($invalidResults as $invalid): ?>
<li class="error-item"><?= htmlspecialchars($invalid['invalid']) ?> - <?= htmlspecialchars($invalid['reason']) ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form method="post" class="download-buttons">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<input type="hidden" name="input_data" value="<?= htmlspecialchars($_POST['input_data']) ?>">
<?php if (count($validResults) > 0): ?>
<button type="submit" name="download_valid" class="btn">Download Valid Results</button>
<?php endif; ?>
<?php if (count($invalidResults) > 0): ?>
<button type="submit" name="download_invalid" class="btn btn-error">Download Invalid Results</button>
<?php endif; ?>
</form>
</div>
<?php endif; ?>
</div>
</body>
</html>

135
index3-old.php Normal file
View File

@ -0,0 +1,135 @@
<?php
// Set headers to prevent search engines from indexing the page
header("X-Robots-Tag: noindex, nofollow", true);
// Start session for CSRF token
session_start();
// Generate a CSRF token if one isn't set
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
// Function to process input data
function processInput($input) {
// Step 1: Remove any non-numeric characters
$cleanedInput = preg_replace('/\D+/', '', $input);
// Step 2: Filter only 17 digits long strings
if (preg_match('/^\d{17}$/', $cleanedInput)) {
// Step 3: Check if the first four digits are within 2004-2018
$firstFourDigits = substr($cleanedInput, 0, 4);
if ($firstFourDigits >= 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;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow">
<title>Input Validator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Input Validator</h1>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post">
<label for="input_data">Enter your data (one per line):</label><br>
<textarea id="input_data" name="input_data" rows="10" cols="50"><?= isset($_POST['input_data']) ? htmlspecialchars($_POST['input_data']) : '' ?></textarea><br><br>
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<button type="submit" class="btn">Process</button>
</form>
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error): ?>
<div class="results">
<h2>Results</h2>
<p>Input Rows: <strong><?= count($rows) ?></strong></p>
<p>Valid Output Rows: <strong><?= count($validResults) ?></strong></p>
<p>Invalid/Discarded Rows: <strong><?= count($invalidResults) ?></strong></p>
<?php if (count($invalidResults) > 0): ?>
<h3 class="error-title">Discarded Inputs:</h3>
<ul class="error-list">
<?php foreach ($invalidResults as $invalid): ?>
<li class="error-item"><?= htmlspecialchars($invalid['invalid']) ?> - <?= htmlspecialchars($invalid['reason']) ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form method="post" class="download-buttons">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<input type="hidden" name="input_data" value="<?= htmlspecialchars($_POST['input_data']) ?>">
<?php if (count($validResults) > 0): ?>
<button type="submit" name="download_valid" class="btn">Download Valid Results</button>
<?php endif; ?>
<?php if (count($invalidResults) > 0): ?>
<button type="submit" name="download_invalid" class="btn btn-error">Download Invalid Results</button>
<?php endif; ?>
</form>
</div>
<?php endif; ?>
</div>
</body>
</html>

121
style.css Normal file
View File

@ -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;
}
}