我有一个php文件,每次加载时都会向我发送一封电子邮件。没有用户输入字段,它不是联系人表单或任何其他表单。它只是一个重定向php文件,每次加载时我都想收到电子邮件。我在其中包含了以下php邮件功能,并想知道它是否有任何安全问题(由于没有用户输入字段,我希望我可以这样离开它):
$to = 'myemail@gmail.com';
$subject = 'the file is loaded';
$message = 'the file loaded, check it out';
$headers = 'From: webmaster@mywebsite.com' . "'r'n" .
'Reply-To: webmaster@mywebsite.com' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
从功能角度来看,这是完全安全的。您的电子邮件无法更改。
然而,如果一个人决定攻击你,他可以在很短的时间内给你发送数量惊人的电子邮件。你的主机或ISP会对此感到愤怒。
排队可以避免这种情况。获取数据库或文件,保存调用页面的次数以及上次发送电子邮件的时间。
如果脚本被调用,并且上次发送的电子邮件是x分钟前,则可以向自己发送一条消息,说明该页面已被调用x次。然后,您只需清空数据库并重新开始计数:)
这里有一个脚本,让你开始(尚未测试)
// Duration in seconds
$duration = 60 * 15;
$now = time();
$file = 'tmp.json';
$json = json_decode(file_get_contents($file));
array_push($json['calls'], $now);
// It appears it's time to send the content
if($json['sent'] + $duration > $now) {
$to = 'myemail@gmail.com';
$subject = 'the file is loaded';
$headers = 'From: webmaster@mywebsite.com' . "'r'n" .
'Reply-To: webmaster@mywebsite.com' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
$message = '';
// Generate message
foreach($json['calls'] as $c) {
$message .= sprintf("File loaded at: %s'r'n", date('r', $c));
}
if(mail($to, $subject, $message, $headers)) {
// Reset the file but ONLY if the mail was sent
file_put_contents($file, json_encode(array(
'calls' => array(),
'sent' => $now
)));
}
} else {
file_put_contents($file, json_encode($json));
}
您可以完全控制静态内容的电子邮件可能存在哪些安全问题。不管怎样,我相信如果你只在本地文件或数据库中跟踪你的文件加载情况会更好。祝你好运:P