Simple visitor counter

This is the right place to report general bugs, make suggestions or ask for help.
Post Reply
joticakr
Posts: 18
Joined: Sat Apr 17, 2021 4:58 pm

Simple visitor counter

Post by joticakr » Thu Aug 26, 2021 4:11 pm

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

User avatar
Arvid
FlatPress Coder
Posts: 558
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Simple visitor counter

Post by Arvid » Sun Aug 29, 2021 11:00 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests