我正在为我的团队制作一个网站,该团队拥有几个游戏服务器。在这个过程中,我做了一个网站,ping服务器,并在返回显示是否它是上升或下降。我希望能够说,如果它失败了,你可以给我发邮件。这部分有效。我不想要的是用户发过一次邮件后还能继续给我发邮件。
我想知道我是否可以以某种方式制作一个脚本,当任何用户点击链接给我发电子邮件时,NO其他用户可以给我发电子邮件大约一个小时。我想这应该是服务器端。我在过去做了一个脚本,它的工作原理是,当有人点击链接时,它会增加一个小时。问题是,当用户回到那个目录时,他们可以再次点击它,因为时间没有节省。我也希望它,如果多个用户点击链接在同一时间只增加1小时,而不是多个(例如,3个用户在网站2个用户点击通知,它会增加2小时,而不是仅仅1。)
任何正确方向的提示都会很好。我想过使用MySQL,但不想,除非绝对需要(不知道如何可能与我们的数据库设置)
另一种选择是在服务器上的某个地方放置一个文件,其中包含一个文件,其中写入了最后发送消息的时间,然后将其与当前时间进行比较。下面是一个粗略的示例(请注意,该示例不安全,需要在接受原始用户输入之前进行清理,但希望它能为您指明正确的方向):
<?php
send_email();
function maindir() {
// This will need to be set to the directory containing your time file.
$cwd = '/home/myusername/websites/example.com';
return $cwd;
}
function update_timefile() {
$cwd = maindir();
// The file that will contain the time.
$timefile = 'timefile.txt';
$time = time();
file_put_contents("$cwd/$timefile", $time);
}
function send_email() {
// Note: this should be sanitized more and have security checks performed on it.
// It also assumes that your user's subject and message have been POSTed to this
// .php file.
$subject = ($_POST && isset($_POST['subject']) && !empty($_POST['subject'])) ? $_POST['subject'] ? FALSE;
$message = ($_POST && isset($_POST['message']) && !empty($_POST['message'])) ? $_POST['message'] ? FALSE;
if ($subject && $message) {
$to = 'me@example.com';
$cwd = maindir();
$timefile = 'timefile.txt';
// Current time
$timenow = time();
// Read the time from the time file
$timeget = file_get_contents("$cwd/$timefile");
// Calculate the difference
$timediff = $timenow - $timeget;
// If the difference is greater than or equal to the current time + 3600 seconds..
if ($timediff >= 3600) {
// ... and if the message gets sent...
if (mail($to, $subject, $message)) {
// ... update the time file.
update_timefile();
}
}
}
}