04 Sessions Mysql 02 Session 02

04 Sessions Mysql02 Session 02

Who are you?

Login

$_SERVER["SCRIPT_NAME"]
/php/assignments/04-sessions-mysql/02-session-02.php

print_r($_GET)
Array
(
)


print_r($_POST)
Array
(
)


print_r($_SESSION)
Array
(
)


print_r($_FILES)
Array
(
)



<?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'];
}

$tools true;
include(
"../../includes/header.php");
?>

<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&hellip;</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");
?>