0

我正在使用 php 发送邀请邮件mail()。我想跟踪有多少人接受邀请和拒绝邀请。我使用两个按钮来接受和拒绝。如何实现点击计数器?如果不将页面从邮件重定向到我的网站,是否可以更新计数?

4

1 回答 1

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);
}
于 2018-03-08T06:42:01.237 回答