<?php
// Attempt to retrieve the user's name from their cookie -
// First - check if we have a name for them:
$has_name = isset( $_COOKIE['name'] );
// Second - set a $name variable either to their name (if we have it) or "Stranger" if we don't:
$name = $has_name ? $_COOKIE['name'] : 'Stranger';
// Remember that the user's name is user input and therefore untrustworthy -
// We'll need to use htmlspecialchars() to escape it and prevent XSS attacks!
?>
<h1>You found the second page, <?php echo htmlspecialchars( $name ); ?>!</h1>
<p>
This website isn't very interesting. You might as well go back to the
<a href="/demo-harness.php?file=public/appendix-samples/remember-my-name.php">first page</a> again.
</p>