Skip to content

Instantly share code, notes, and snippets.

@oschettler
Last active January 24, 2023 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oschettler/8073680f9458317989e9244022b5ab5b to your computer and use it in GitHub Desktop.
Save oschettler/8073680f9458317989e9244022b5ab5b to your computer and use it in GitHub Desktop.
A small form handler
<?php
$dir = "/var/www/lena/reg";
$pattern = '/(\d{4}\d{2}\d{2}_\d{2}\d{2}\d{2})/';
if (isset($_GET['list'])) {
echo "<h1>Liste</h1><ul>";
foreach (glob("{$dir}/*.txt") as $f) {
if (preg_match($pattern, $f, $m)) {
$d = $m[1];
echo "<li><a href=\"?r={$d}\">{$d}</a></li>\n";
}
}
echo "</ul>";
exit();
}
else
if ($_GET['r']) {
$d = $_GET['r'];
if (preg_match($pattern, $d)) {
$c = htmlentities(file_get_contents("{$dir}/{$d}.txt"));
echo "<meta charset=\"utf-8\"><h1>{$d}</h1><pre>{$c}</pre><p><a href=\"?list\">zurück zur Liste</a></p>\n";
}
exit();
}
$data = '';
foreach ($_POST as $n => $v) {
$data .= "$n = $v\n";
}
$fname = strftime("{$dir}/%Y%m%d_%H%M%S.txt");
file_put_contents($fname, $data);
header('Location: https://steinsekte.xyz/reg.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment