A PHP session is a way to store information on the server to be used across multiple pages of a web application. Unlike cookies, which store data on the user’s computer, session data is stored on the server. This function must be called at the beginning of your script, before any other HTML tags.
<?php
session_start();
if(isset( $_SESSION['demo_count'] )) {
$_SESSION['demo_count'] += 1;
}
else {
$_SESSION['demo_count'] = 1;
}
$demo_message = "<strong>" . $_SESSION['demo_count'] . "</strong>.";
?>
<html>
<head>
<title>Session Demo</title>
</head>
<body>
<?php echo $demo_message; ?>
</body>
</html>