Customer Support

  1. Support
  2. FTP/ File Manager
  3. How can I add a Site Counter to a page on my site?
  1. Home
  2. Plesk
  3. How can I add a Site Counter to a page on my site?

How can I add a Site Counter to a page on my site?

The following code displays a site counter on the page where you add it. The code is in PHP, so the page must be implemented in PHP. If your page is a simple static HTML or HTM, just rename it to PHP. The process of adding the site counter is straightforward.
  1. First, add the following line to the beginning of the PHP page where you want the counter:
<?php
  1. Then, at the point where you want to display the number of visitors (Site Counter), add the following code:
list($count) = @file('count.txt'); if (!is_numeric($count)) $count = 0; if (!isset($_COOKIE['unique'])) { $fp = @fopen('count.txt', 'w'); @fwrite($fp, ++$count); @fclose($fp); $count = (string) $count; } // Text Counter echo "Number of Visitors: $count!<br>"; // Digital Counter echo '<img src="path/to/image'.$count.'.png">'; ?> 3. You can delete the line under "// Text Counter" or "// Digital Counter" depending on the type of counter you want to display on your site. For the Digital Counter, you will need to upload the related images to your site. Search Google for "counter digits" to find free images for Site Counters. 4. Open the page in your browser. It should display the number 1. Each unique visitor counts as one visit, regardless of how many times they open the page. The visit count is stored in the "count.txt" file. If the visitor count does not increase, make sure the file is writable.

You haven't found what you are looking for?

Contact our experts, they will be happy to help!

Contact us