How to add or create a counter on your web page

Updated: 12/31/2022 by Computer Hope
Counter displaying the numbers 1842.

Putting a hit counter (page counter) on a web page helps you track how many visitors visit your web page. There are several ways to go about putting a counter on your page, either by adding a pre-built one or creating your own.

Tip

We highly recommend using the Google Analytics over any web page counter, as it gives you more valuable information.

Adding a pre-built counter

If you prefer to add a pre-built counter to your web page, here are a few ways to do so.

  • Check with the web host for your web page. Often the company hosting your web page offer free solutions and provide instructions on how to add the counter code to your web page.
  • Acquire a pre-built counter from websites that offer free counters and add it to your web page with only a few lines of code. We recommend the following sites for free counters.

Example of the free counter stat

website hit counter

Note

A counter like the one used above increases in count if you or any visitor refreshes their browser. For example, if you refresh this page, the above counter would increase. If other people have visited since you first loaded the page, the counter may go up by several numbers.

Create a counter

To create a counter, you must create a Perl, PHP (PHP: Hypertext Preprocessor), or another script. Then, either refer to that script through a server-side include or another method. We recommend you already know or learn Perl or PHP programming to create the counter script.

The code for creating a counter can vary, depending on the programming language used and the type of counter you want to add to your web page. Below are some web pages that offer sample counter script code to use as a guide for creating a counter.

Note

We have not tested the sample counter scripts provided on these web pages, so we cannot guarantee they're bug-free.