Reputation: 359
I am sending invitation mails using php mail()
. I want to track how many people accept invitation and declined invitation. I am using two buttons for accept and decline. How can I implement click counter? Is it possible update count without redirecting page from mail to my website?
Upvotes: 0
Views: 288
Reputation: 908
Create a file on your server: counter
create a PHP file which increases or decreases the number in the counter
file.
Increase:
$readf = fopen("counter", "r"); //open the file in read mode
$count = fread($readf,filesize("counter")); //read the content in it
fclose($readf); //close the file in read mode
$writef = fopen("counter", "w+"); //open the file in overwrite mode
$count++; //increase the count by one
fwrite($writef, $count); //write changes to the file
fclose($writef); //close the file in overwriting mode
Decrease:
$readf = fopen("counter", "r");
$count = fread($readf,filesize("counter"));
fclose($readf);
$writef = fopen("counter", "w+");
$count--;
fwrite($writef, $count);
fclose($writef);
Make sure the file counter
exists in the first place with the count 0:
if(!filesize("count")){
$writef = fopen("counter", "w+");
fwrite($writef, "0");
fclose($writef);
}
Upvotes: 2