Creating a Simple Counter with Sessions in PHP


Use a session to create a page visit counter.

Source Code

session_start();
if (!isset($_SESSION['counter'])) {
    $_SESSION['counter'] = 1;
} else {
    $_SESSION['counter']++;
}
echo "You have visited this page ".$_SESSION['counter']." times.";
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments