Basic Session Handling in PHP
Start a session, store a value, and read it on the next request.
Author:
chris
// Language: PHP
<?php
declare(strict_types=1);
session_start([
'cookie_httponly' => true,
'cookie_secure' => true,
'cookie_samesite' => 'Lax',
]);
$_SESSION['visits'] = ($_SESSION['visits'] ?? 0) + 1;
echo "You have visited {$_SESSION['visits']} times.";