【发布时间】:2015-08-23 08:50:43
【问题描述】:
我有一个评论系统,用户可以在其中发布他们对某些事情的看法,但是如果您按“发布!”多次按钮,多个查询被插入到数据库中,结果是垃圾邮件。
这是我的代码:
if(!empty($_POST["artcomment"])) {
$postComment = $DB->real_escape_string($_POST["artcomment"]);
$poster = $dbuser;
$postDate = date("Y-m-d H:i:s");
$attachId = $id;
$prepareComment = $DB->prepare("INSERT INTO article_comments (attach_id, comment, poster, date) VALUES ('".$attachId."', '".$postComment."', '".$poster."', '".$postDate."')");
$addComment = $prepareComment->execute();
}
现在我想知道是否可以设置 60 秒的时间限制,就好像他们运行一次查询(单独!)你必须等待 60 秒才能再次执行查询。我看过set_time_limit(),但我不完全确定它是如何工作的。
【问题讨论】:
-
旁注:使用prepared statement and variable binding而不是手动转义字符串并将数据填充到SQL查询中。
-
real_escape_string() 和 prepare()?这有点可疑!
标签: php mysqli spam time-limiting