Page 1 of 1

Simple visitor counter

Posted: Thu Aug 26, 2021 4:11 pm
by joticakr
Hello all,

new day, new question... ;)
I try to implement a simple visitor counter on my page like this:

Code: Select all

$counter = fopen("counter.md","r+");
$wert = fgets($counter, 5);
if($wert == "") $wert = 0;
$wert++;
rewind($counter);
fwrite($counter, $wert);
fclose($counter);
If I put this code in the index.php I get one count for each static page my visitor clicks and also one count for every page refresh.
Is it possible to avoid this behaviour if I add the code at an other position? If yes, I coudn't figure out where.

I'm also open for other solutions.

Thanks for your help,
Johannes

Re: Simple visitor counter

Posted: Sun Aug 29, 2021 11:00 am
by Arvid
Johannes, you are only one step ahead of creating your first FlatPress plugin :) And this is exactly what would be the best way to go here.
Unfortunately, the wiki still misses a guide on how to start creating plugins. I for myself started by just reading the code of other plugins.