<?php require '../includes/config.php'; session_start(); if (isset($_POST)) { $curr_vote = ($v = post_rel($_POST["post_id"])) ? $v["vote"] : "NONE"; $json = []; if ($curr_vote == $_POST["vote"]) { $json["msg"] = "Already voted."; } switch ($_POST["vote"]) { case 'UP': $json["res"] = upvote_post($_POST["post_id"]); break; case 'DOWN': $json["res"] = downvote_post($_POST["post_id"]); break; case 'UNVOTE': $json["res"] = unvote_post($_POST["post_id"]); break; } echo json_encode($json); }
<?php session_start(); include "../config.php"; include "../functions.php"; include "../private_functions.php"; if (isset($_SESSION['auth']) && $_SESSION['auth'] == 1 && isset($_GET['pID'])) { $dbh = db_connect($MY_HOST, $MY_DB_PORT, $MY_DB, $DB_USER, $DB_PW); if (already_voted($dbh, $_SESSION['user'], $_GET['pID'])) { $res = unvote_post($dbh, $_SESSION['user'], $_GET['pID']); close_db_connection($dbh); echo json_encode($res); } else { echo json_encode(array("status" => -2)); } } else { echo json_encode(array("status" => -1)); }