Probably a dumb question but I just started learning PHP and now I have to do an exercise in which, on the one hand, the session variables have to count how often you have visited the page before closing the browser. And on the other hand, the cookies should count how often you have visited a website in total. So also if you have closed your web browser, the cookie should continue counting. This is my problem though. If I close my web browser and start it again, the cookie starts all over again with counting. How to solve this?
PHP File
<?php
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 1;
} else {
$_SESSION['count']++;
}
echo "You have visited this page " . $_SESSION['count'] . " times before you closed your browser";
$count = $_SESSION['count'];
setcookie("count", "$count", time() + 3600);
if (!isset($_COOKIE['count'])) {
$_COOKIE['count'] = ($_COOKIE['count'] + $_SESSION['count']);
} else {
$_COOKIE['count']++;
}
echo "<br> In total you have visited this page " . $_COOKIE['count'] . " times";
?>