我正在为我的团队制作一个网站,其中有几个游戏服务器。在这个过程中,我制作了一个网站,点击服务器,作为回报,显示它是向上还是向下。我想说,如果它是坏的,你可以发邮件给我。那部分起作用。我不想让一个用户在他们发了一次邮件后继续给我发邮件。
我想知道我是否可以做一个脚本,当任何用户点击链接给我发电子邮件时,没有其他用户可以给我发一个小时的电子邮件。我想这必须是服务器端的东西。我在过去做了一个脚本,当有人点击链接时,它可以工作一个小时。问题是,当用户返回到该目录时,他们可以再次单击它,因为时间没有节省。我还希望,如果多个用户同时单击该链接,它只会增加1个小时,而不是多个小时(例如,3个用户在网站上单击“通知”,就会增加2个小时,而不是仅仅增加1个小时。)
任何正确方向的暗示都会很好。我考虑过使用MySQL,但是除非绝对需要,否则我不想使用(不知道我们的数据库设置有多可能)。
发布于 2015-07-12 02:06:53
另一种选择是让一个文件位于服务器的某个位置,其中包含一个文件,其中包含在其中写入最后一条消息的时间,然后将其与当前时间进行比较。下面是一个粗略的示例(请注意,该示例不安全,需要在接受原始用户输入之前进行净化,但希望它将为您指明正确的方向):
<?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();
}
}
}
}https://stackoverflow.com/questions/31363498
复制相似问题