id)) { $cms_post->note = $cms_post->note + 1; $cms_post->save(); $result['nb_vote'] = $cms_post->note; $result['already_vote'] = false; } else { $result['nb_vote'] = $cms_post->note; $result['already_vote'] = true; } die(Tools::jsonEncode($result)); } else { $result['errors'] = true; die(Tools::jsonEncode($result)); } function checkCookie($id_post) { if (isset($_COOKIE['voting'])) { $cookie = utf8_decode($_COOKIE['voting']); if ($cookie != 0) { $already_vote = explode(',', $cookie); if (in_array($id_post, $already_vote)) { return true; } else { $vote = ''; for ($i=0; $i < (sizeof($already_vote)-1) ; $i++) { $vote.= $already_vote[$i].','; } $vote.=$id_post.','; setcookie("voting", utf8_encode($vote), time()+(60*60*24*300), '/'); return false; } } else { $vote = $id_post.','; setcookie("voting", utf8_encode($vote), time()+(60*60*24*300), '/'); return false; } } else { setcookie("voting", utf8_encode('0'), time()+(60*60*24*300), '/'); return false; } }