<?php // initiate session session_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 session variable is set if (isset($_SESSION['name'])) { // if set, greet by name echo "<h2>Hi, {$_SESSION['name']} </h2>"; echo '<p><a href="03-session-03.php">Goto Next Page…</a></p>'; } else { // if not set, send back to login echo '<h2>Who are you?</h2>'; echo '<p><a href="01-session-01.php">Login</a>'; } ?> </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"); ?>