<?php // initiate session session_start(); // output buffer start - don't send any http packets to browser until ob_end_flush(); ob_start(); // check that form has been submitted and that name is not empty if ($_POST && !empty($_POST['name'])) { // set session variable $_SESSION['name'] = $_POST['name']; }
<main> <h2><?php echo $folder_name; ?><span><?php echo $file_name; ?></span></h2> <?php // check whether session variable is set if (isset($_SESSION['name'])) { // if set, greet by name echo "<h2>Hi, {$_SESSION['name']}</h2>"; echo '<p>See, I remembered your name!</p>'; // unset session variable unset($_SESSION['name']); // invalidate the session cookie if (isset($_COOKIE[session_name()])) { // name value expire path setcookie(session_name(), '', time() - 86400, '/'); } // ob_end_flush() - now it is okay to send http packets to browser ob_end_flush(); // end session session_destroy(); echo '<p><a href="02-session-02.php">Page 2</a><p>'; } else { // display if not recognized echo "<h2>Sorry, I don't know you.</h2>"; echo '<p><a href="01-session-01.php">Login</a></p>'; } ?> </main>
<?php # The side-bar section of the layout use custom path to load from a different folder. include("../../includes/sidebar.php");
# The footer section of the layout. include("../../includes/footer.php"); ?>