如何限制Facebook应用程序中的投票功能,每天一次
How to limit voting function in a Facebook App once per day?
我对后端工作很陌生,我正在构建一个带有投票机制的多张照片的Facebook应用程序。你可以每天对一个或多个条目进行一次投票,它还会检测你的Facebook ID,这样当你投票时,数据库就会检测你的脸书ID、你投票的条目号和你投票的日期。当你在当前日期投票时,会出现一个弹出窗口,上面写着"你成功投票了"。然后,当你在同一日期再次尝试时,弹出窗口的消息会发生变化,取而代之的是,它会说"明天再尝试投票"。它还显示了参赛页面上的票数。
我唯一的问题是,当你是第一次用户时,它运行良好,你可以在当前日期对所有条目进行投票,但当你第二天回来投票时,弹出窗口仍然会显示你已经投票,并且计票不会更新。
以下是PHP页面的代码:(编辑了这个,已经解决了问题,感谢您的帮助)
date_default_timezone_set('Asia/Manila');
// Get last vote date: fetch_date_voted returns none if user voted for first time
$current_date = date('Y-m-d');
$fetch_date_return = $this->fetch_date_voted($entry_id, $facebook_id, $table_prefix, $conn);
$last_vote_date = $fetch_date_return['last_date'];
$return['date_last_voted'] = $fetch_date_return;
// Below is a code i got from stackoverflow - 844641242329946 (kristina id)
/*if( $last_vote_date && ($last_vote_date == "none" || (strtotime($last_vote_date) + (60*60*24)) < strtotime($current_date))){*/
// Below is the original code
if( $last_vote_date == "none" || $last_vote_date < $current_date ) {
$table_name = $table_prefix . '_voter';
$query = $conn->query("
INSERT INTO $table_name
(facebook_id, entry_id, date_voted)
VALUES
($facebook_id, $entry_id, '$current_date')
");
//
// After doing INSERT, the variable $query will return a TRUE status
if ( $query ) {
// If the date fetched is TRUE, it will UPDATE
$update = $this->update_count($entry_id, $table_prefix, $conn);
// If update is successful, it will fetch the latest vote_count
if($update) {
$fetched_data = $this->fetch_current_count($entry_id, $table_prefix, $conn);
if ($fetched_data['status']) {
$return['status'] = true;
$return['vote_count'] = $fetched_data['vote_count'];
} else {
$return['status'] = false;
}
} else {
$return['status'] = false;
}
} else {
die('Error : ('. $conn->errno .') '. $conn->error);
$return['status'] = false;
$return['error_response'] = $conn->error;
}
} else {
$return['status'] = false;
$return['error_response'] = 'date_invalid';
}
echo json_encode($return);
//$query->close();
$conn->close();
}
$last_vote_date和$current_date是日期的字符串表示,将它们转换为时间,它就起作用了:
strotime($last_vote_date) < strotime($current_date)
请注意,这将始终返回true,因为你希望他们一天都不要使用它,所以它将是:
if( $last_vote_date && ($last_vote_date == "none" || (strtotime($last_vote_date) + (60*60*24)) < strtotime($current_date))){
增加24小时。
相关文章:
- Javascript返回值只在循环中返回一次
- Jquery FadeIn FadeOut 只工作一次
- Javascript html每点击一次就会更改url
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- jQuery滚动功能只工作一次
- 刷新导致我的帖子“;张贴“;再一次
- 引导程序崩溃一次只能看到一个
- 有没有一个抽象层,这样我就可以集成一次,然后使用pusher、pubnub或faye
- ¿如何每天只显示一次特定的容器
- 如何对每个用户每天只允许单击一次的按钮进行编码
- 每天递减一个变量一次 - Javascript
- 每天为每个新用户运行一次 JavaScript 函数
- 如何在Java/javascript中每天更改一次变量的值
- Javascript通知栏-使其每天只显示一次
- 如何在Chrome扩展中每天只运行一次脚本
- 油脂猴子每天运行一次脚本
- 如何在特定时间重新加载页面,并且每天只加载一次
- 强制JavaScript每天重新加载一次
- 如何使用 jQuery 每天减少一次商店数量计数