Last active
January 24, 2023 20:42
-
-
Save oschettler/8073680f9458317989e9244022b5ab5b to your computer and use it in GitHub Desktop.
A small form handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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