I want to make a code that when someone presses a button like: "Click me" it will count as a click and it will save on the .txt
<?php
if (file_exists('count_file.txt'))
{
$fil = fopen('count_file.txt', r);
$dat = fread($fil, filesize('count_file.txt'));
echo $dat+1;
fclose($fil);
$fil = fopen('count_file.txt', w);
fwrite($fil, $dat+1);
}
else
{
$fil = fopen('count_file.txt', w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}
?>
I used that script but I want that it only works with nclick="javascript:countClicks(); so not when you refresh the page or something
How can I get this working?