I am trying to add a simple ‘I Like This’ text button to pieces of my work. When the user clicks the ‘I like this’ button, I want a number to be recorded right next to the button, showing the total number of ‘likes’ so far. This is the first time I am using PHP to do anything, so I am completely lost - I can’t get any click counter to work that is simple enough for what I want to do and that will work without a MySQL database.
So far I have managed to set up a Javascript counter and it works great, but obviously it doesn’t remember the clicks once the user reloads the page - I need a permanent click counter. If this can be achieved using Javascript only, that would be ideal - but I don’t think there’s a way. Here is the code I have so far, and I just can’t get this to work:
CODE IN MY HTML PAGE (index.html):
I like it! <?php include("counter.php"); ?>
CODE IN MY PHP FILE (counter.php)
<?php
$filename = “counter.txt”;
$count= file($filename);
$count[0]++;
$file = fopen ($filename, “w”) or die (“Cannot find $filename”);
fputs($file, “$count[0]”);
fclose($file);
echo $count[0];
?>
TEXT FILE SAVED IN THE SAME DIRECTORY (counter.txt)
0
I think I might be calling the php file incorrectly in the my html page?
Can anyone help me? I am going to kill myself. Thanks