04 Sessions Mysql 03 Session 03

04 Sessions Mysql03 Session 03

Sorry, I don't know you.

Login

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

print_r($_GET)
Array
(
)


print_r($_POST)
Array
(
)


print_r($_SESSION)
Array
(
)


print_r($_FILES)
Array
(
)



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



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

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