我正在使用php mail()
发送邀请邮件。我想跟踪有多少人接受邀请并拒绝邀请。我使用两个按钮接受和拒绝。我该如何实现点击计数器?是否可以更新计数而不将页面从邮件重定向到我的网站?
答案 0 :(得分:2)
在您的服务器上创建一个文件:counter
创建一个PHP文件,增加或减少counter
文件中的数字。
上调:
$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
减少:
$readf = fopen("counter", "r");
$count = fread($readf,filesize("counter"));
fclose($readf);
$writef = fopen("counter", "w+");
$count--;
fwrite($writef, $count);
fclose($writef);
确保文件counter
首先存在于计数0:
if(!filesize("count")){
$writef = fopen("counter", "w+");
fwrite($writef, "0");
fclose($writef);
}