Don Alexander Eckford's SESSION Management Demo (Page 1)

Welcome, Don Alexander!

This page demonstrates how session variables are initialized and stored.

Your session ID is: a4d3c207ec17ce1ca100efc27b38f713

You have visited this page 1 times in this session.

Go to Page 2
Array
(
    [username] => Don Alexander
    [count] => 1
)
 

CODE FOLLOWS

<?php
// Start a session
session_name("session_demo");
session_start();

include(
'includes/header.php');

// Set error reporting for development purposes
error_reporting(E_ALL);
ini_set('display_errors'1);

// Initialize session variables if not already set
if (!isset($_SESSION['username'])) {
    
$_SESSION['username'] = "Don Alexander";
}

if (!isset(
$_SESSION['count'])) {
    
$_SESSION['count'] = 0;  // Initialize a counter in the session
}

// Increment the session count variable each time the page is refreshed
$_SESSION['count']++;

// Display the session ID
$session_id session_id();

?>

<!-- HTML Content -->
<h1>Don Alexander Eckford's SESSION Management Demo (Page 1)</h1>

<p>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</p>
<p>This page demonstrates how session variables are initialized and stored.</p>
<p>Your session ID is: <?php echo htmlspecialchars($session_id); ?></p>
<p>You have visited this page <?php echo $_SESSION['count']; ?> times in this session.</p>

<!-- Link to Page 2 for further session variable manipulation -->
<a href="session_dae_page2.php">Go to Page 2</a>

<!-- Link to reset the session -->
<form action="reset_dae_session.php" method="post">
    <input type="submit" value="Reset Session">
</form>

<?php
// Optional: Display all session variables for debugging purposes
echo '<pre>';
print_r($_SESSION);
echo 
'</pre>';

include(
'includes/footer.php');
?>