PHP program to find number of page views

By | August 13, 2016

A PHP program to store page view count in a SESSION variable and to increment the count on each web page refresh. This session variable is displayed on the web page which contains the number of page views count.



Suggested Read:


The following code can be used to reset the views count to 1.

The output on the browser:

PHP program to find number of page views using session

shows the initial count

PHP program to find views count using session

Count after the first refresh


How to execute this PHP Script?

  1. You need to copy the file ViewsCount.php to a PHP server. You can use wampserver software which provides an integrated environment to run PHP files along with MySQL database support.
  2. Next, open this PHP file on the browser via localhost URL. Usually http://localhost/ViewsCount.php
  3. Initially, your browser will display the result  as views=1
  4. Refresh the web page to check the increase in page views.

Please let me know if you come across any issues.

Suggested articles for you:

Did it help? Comment here..