1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <?php error_reporting(0);
if (isset($_GET['source'])) { show_source(__FILE__); exit(); }
function is_valid($str) { $banword = [ "[\"%'*+\\/<=>\\\\_`~-]", '\s', 'blob', 'load_extension', 'char', 'unicode', '(in|sub)str', '[lr]trim', 'like', 'glob', 'match', 'regexp', 'in', 'limit', 'order', 'union', 'join' ]; $regexp = '/' . implode('|', $banword) . '/i'; if (preg_match($regexp, $str)) { return false; } return true; }
header("Content-Type: text/json; charset=utf-8");
if (!isset($_POST['id']) || empty($_POST['id'])) { die(json_encode(['error' => 'You must specify vote id'])); } $id = $_POST['id']; if (!is_valid($id)) { die(json_encode(['error' => 'Vote id contains dangerous chars'])); }
$pdo = new PDO('sqlite:../db/vote.db'); $res = $pdo->query("UPDATE vote SET count = count + 1 WHERE id = ${id}"); if ($res === false) { die(json_encode(['error' => 'An error occurred while updating database'])); }
echo json_encode([ 'message' => 'Thank you for your vote! The result will be published after the CTF finished.' ]);
|