Esempio n. 1
0
 public function IpLimit($ip)
 {
     //Cookie伪验证,如果要真实验证需配合数据库或Memcache
     $addComment = Request::getCookie('comment_ip');
     if (isset($addComment)) {
         $count = Request::getCookie('comment_ip_comments');
         if ($count > 20) {
             AjaxError('sorry..每天评论不能超过12条');
         } else {
             Request::setCookie('comment_ip_comments', $count + 1, time() + 86400);
         }
     } else {
         Request::setCookie('comment_ip', $ip, time() + 86400);
         Request::setCookie('comment_ip_comments', 1, time() + 86400);
     }
 }
 public function scoreajax()
 {
     if ('POST' != $_SERVER['REQUEST_METHOD']) {
         header('Allow: POST');
         header('HTTP/1.1 405 Method Not Allowed');
         header('Content-Type: text/plain');
         die('Illegal request!');
     }
     $fields = array();
     $fields['action'] = isset($_POST['action']) ? intval($_POST['action']) : null;
     $fields['um_action'] = isset($_POST['um_action']) ? trim($_POST['um_action']) : null;
     $fields['um_id'] = isset($_POST['um_id']) ? intval($_POST['um_id']) : null;
     $data = array();
     $addScore = Request::getCookie('add_score_' . $fields['um_id']);
     //判断是否24小时内已经投过了。cookie判断,伪验证!安全点就使用ip验证。
     if (!empty($addScore) && $addScore - time() <= 86400) {
         AjaxError('24小时内只能投一次');
     }
     Request::setCookie('add_score_' . $fields['um_id'], time(), time() + 86400);
     $article = self::$models->Article;
     if ($fields['um_action'] == 'ding') {
         $result = $article->updatePlus($fields['um_id'], 'good_num');
     } elseif ($fields['um_action'] == 'xu') {
         $result = $article->updatePlus($fields['um_id'], 'bad_num');
     }
     echo $result ? $fields['action'] + 1 : '不明所以的失败了...';
 }