Website Visits count

I just want every time some loads my website, it counts. or in another word every time someone views my website it counts.

Are you looking for something like this or do you want to code something yourself?

This one works well. easycounter.com

Just getting a count of page requests is rather worthless. Your server should already be logging every request with plenty of details. The who, what, where and when and how. Just use a server log analyzer. Here is an example of what you can get from your logs…

https://rt.goaccess.io/?20200624200721

1 Like

something i code myself.

You’re not going to do it in HTML or CSS. You’ll need a server-side script.

Please supply more details about the site.

does it use Apache2, etc.

If you use PHP and have a common footer or header for every page then a simple file update should suffice.

I use php and i want to have the results displayed on footer.

Well this might do the trick

$file = 'count.txt';
if (!file_exists($file)) {
  $fp = fopen($file, "w+");
  fwrite($fp, "0");
  fclose($fp);
}
$fp = fopen($file, "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
$count++;
fseek($fp, 0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
echo $count;
1 Like

ill need to create count.txt file? no coontent in it?

No, the script does that for you first time it executes.

It depends on your php ability, as the previous answer says you can update a text file - or you could have a database, say mysql or similar then a php script can be included on every page that will tell you which pages have been visited and how many times, even date and time. But why not simply register with Google Analytics, it’s free, you include a short js on each page and you get all sorts of metrics.

1 Like

Sorry - just seen you want to display results in footer - for me - php / mysql database, but ask yourself do you really want to display this publicly and if so, why?

i am new in this, do i need to enlose the script in <? php script ?>

Yes. Any time you embed PHP into a file, it must be surrounded by opening and closing PHP tags, even if the PHP is the only thing in the file.

1 Like

Don’t forget the file must have a PHP extension, .html will not work.

3 Likes

Does the Google analytics post the stats on your page or does it email them to you?

They have an online dashboard and you can also set up email alerts.

OP, what is the point of having a “page counter”? Those are relics from the 90’s

I can sympathize with you trying to embrace something new. But please first ask yourself why you want to do this. Hit counters as they were called were very popular years ago but faded in popularity because, well basically, people thought they looked naff. Also everybody knew you could artificially ‘inflate’ them, for example you could start rhe counter at 1 million and no one would know, so they were pretty meaningless. Analytics for development and marketing are different and can give valuable feedback on browser types, operating systems, daily and hourly hits per page, geographic location, seach phrases and more. Google analytics is great for this but I don’t think you can automatically display it on your site.
If you do still want to do this then I would stick to my original idea and have a php script on each page you want to monitor. This script would update a mysql database and another script (or the same one) would query the database and display the information. Any php scripts / code must be enclosed in <?php and ?> and the page must have .php extension. The reason I would do it this way is because you could gather and analyse the information as well as display. If you still want to purely increment a counter and display it then a text file approach using javascript would be simpler.
But I would still like to know - why ?

3 Likes