<?php
if (!is_dir("messages")) {
mkdir("messages");
};
a:
goto a;
};
postMessages();
goto a;
};
?>
<?php
// Guestbook, Гостевая книга
if (!is_dir("messages")) {
mkdir("messages");
};
function postMessages() {
foreach (glob('messages/*.txt') as $message) {
$message = file($message);
echo str_replace("\n", "", $message[0]) . "<br/>";
echo str_replace("\n", "", "<a href='mailto:$message[1]'>$message[1]</a>") . "<br/>";
for ($i = 2; $i < sizeof($message); $i++) {
echo htmlspecialchars($message[$i]) . "<br/>";
};
echo "<br/>";
};
};
$messages = scandir("messages");
if (!$_POST) {
postMessages();
//a:
print_form();
} else {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) !== false && $_POST['author'] && $_POST['email'] && $_POST['message']) {
$author = str_replace("\r\n", "", $_POST['author']);
$email = str_replace("\r\n", "", $_POST['email']);
$msg = $_POST['message'];
$time = (int)(microtime(true) * 1000000);
file_put_contents("messages/$time.txt", "$author
$email
$msg");
} else {
echo 'Error while adding your message.';
//goto a;
print_form();
};
postMessages();
//goto a;
print_form();
};
function print_form()
{
echo
'<form action="index.php" method="post">
<p><input type="text" name="author" required /></p>
<p><input type="text" name="email" required /></p>
<p><textarea name="message" required></textarea></p>
<p><input type="submit" /></p>
</form>';
}
?>
if ($_POST) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) && $_POST['author'] && $_POST['message']) {
$author = str_replace("\r\n", "", $_POST['author']);
$email = str_replace("\r\n", "", $_POST['email']);
$msg = $_POST['message'];
$time = (int)(microtime(true) * 1000000);
file_put_contents("messages/$time.txt", "$author\n$email\n$msg");
header("Location:".$_SERVER['REQUEST_URI']);
} else {
echo 'Error while adding your message.';
}
}
postMessages();
?>
<form action="index.php" method="post">
<p><input type="text" name="author" required /></p>
<p><input type="text" name="email" required /></p>
<p><textarea name="message" required></textarea></p>
<p><input type="submit" /></p>
</form>