$name, 'message' => $message]); file_put_contents($book, $entry . "\n", FILE_APPEND | LOCK_EX); setcookie('name', $name, time() + 60 * 60 * 24 * 30); header('Location: /', true, 303); exit; } } $entries = []; if (is_file($book)) { foreach (file($book, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { $entries[] = json_decode($line, true); } } $entries = array_reverse($entries); function e(string $text): string { return htmlspecialchars($text); } ?>
= e($problem) ?>
Nobody has signed yet. Be the first.
= e($entry['name']) ?> wrote: = e($entry['message']) ?>
This page was built at = date('H:i:s') ?>, for one request, and then forgotten.
hello, and look at the page. Then put e() back before you forget. 4. Add a hidden field to the form, , and store it with each entry. Then make a second page, evil.php, holding a form that posts to / with mood set to "furious". The server believes whatever arrives. What does that tell you about hidden fields? 5. Run `php -S localhost:8000` from a different folder, with `-t` pointing at this one. Is the guestbook still there? The line that sets $book says why. 6. Count visits per person with a second cookie, then try to count visits for the whole site. Why does the second one need the file, not a cookie? 7. Store each entry's time with date('c'). PHP picks a time zone for you; find out which one with `php -i | grep timezone`. */