Don Alexander Eckford's SESSION Demo (Page 1)
This adds one to a variable and stores that value in a SESSION.
The following shows the value in the SESSION.
Array ( [var] => 1 )
session_id() = 53ab5a635f9fbe3c59e1ed736f282241
This adds one to a variable and stores that value in a SESSION.
The following shows the value in the SESSION.
Array ( [var] => 1 )
session_id() = 53ab5a635f9fbe3c59e1ed736f282241
<?php
// Start a session with a custom session name "sperlt"
session_name("eckfordd");
session_start(); // Initiates the session or resumes the current one
// Include the header file (assumed to contain common HTML structure)
include('includes/header.php');
// Set error reporting to show all errors and warnings (useful during development)
error_reporting(E_ALL);
ini_set('display_errors', 1); // Ensures errors are displayed (important for debugging)
// Check if 'var' exists in the session, if not, default to 0
$var = isset($_SESSION['var']) ? $_SESSION['var'] : 0;
// Increment the value of 'var'
$var++;
// Store the incremented value back in the session
$_SESSION['var'] = $var;
?>
<!-- HTML Content -->
<h1>Don Alexander Eckford's SESSION Demo (Page 1)</h1>
<p>
This adds one to a variable and stores that value in a SESSION.
</p>
<p>
The following shows the value in the SESSION.
</p>
<!-- Display session variables (for debugging purposes) -->
<?php
echo('<pre>'); // Start preformatted text for readability
print_r($_SESSION); // Print all session variables
echo('</pre>');
echo('<p>session_id() = ' . htmlspecialchars(session_id()) . '</p>'); // Safely display session ID
?>
<!-- Form to move to the next page -->
<form action="session_page2.php" method="post">
<input type="submit" value="GOTO Page 2">
</form>
<?php
// Include the footer file (assumed to contain closing HTML or scripts)
include('../includes/footer.php');
?>