diff options
author | hitlerrip <git@hitler.rip> | 2025-07-29 20:51:12 +0200 |
---|---|---|
committer | hitlerrip <git@hitler.rip> | 2025-07-29 20:51:12 +0200 |
commit | d4b297598e2ffe6890ef4890cba884f875a25c63 (patch) | |
tree | 655f4653b3c0caa334d47be4627814cb03dd9528 | |
parent | 445d3200ba29e9be9b2563b92616bda6399f0577 (diff) | |
download | hitler-clicker-d4b297598e2ffe6890ef4890cba884f875a25c63.tar.gz hitler-clicker-d4b297598e2ffe6890ef4890cba884f875a25c63.tar.bz2 hitler-clicker-d4b297598e2ffe6890ef4890cba884f875a25c63.zip |
click api
added the api that increments all counters
-rw-r--r-- | backend/click.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/backend/click.php b/backend/click.php new file mode 100644 index 0000000..7b8a067 --- /dev/null +++ b/backend/click.php @@ -0,0 +1,62 @@ +<?php +header('Content-Type: application/json; charset=UTF-8'); + +try { + $pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa"); +} catch(PDOException $e) { + die('{ "status": "database offline" }'); +}; + +$wrkarr = []; +$ifarr = [ "token" ]; +$postjson = json_decode(file_get_contents('php://input'), true); +foreach ($ifarr as $i): + if (isset($postjson[$i])): + $newarr = [ + "$i" => "$postjson[$i]", + ]; + $wrkarr = array_merge($wrkarr, $newarr); + endif; +endforeach; + +if (!isset($wrkarr["token"]) || trim($wrkarr["token"]) == ""): + die('{ "status": "token was not provided.\ncould not add a click." }'); +else: + + $query = $pdo->prepare("SELECT token, team, clicks FROM users WHERE token LIKE ?"); + $query->execute([$wrkarr["token"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + $newuserclicks = $found["clicks"] + 1; + + $query = $pdo->prepare("UPDATE users SET clicks = :clicks WHERE users.token = :token"); + $query->execute([ + "clicks" => "$newuserclicks", + "token" => "$wrkarr[token]", + ]); + + $query = $pdo->prepare("SELECT team, clicks FROM stats WHERE team LIKE ?"); + $query->execute([$found["team"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + + $newteamclicks = $found["clicks"] + 1; + + $query = $pdo->prepare("UPDATE stats SET clicks = :clicks WHERE stats.team = :team"); + $query->execute([ + "clicks" => "$newteamclicks", + "team" => "$found[team]", + ]); + + die("{ \"status\": \"success\", \"nuc\": \"$newuserclicks\", \"ntc\": \"$newteamclicks\" }"); + + + else: + die('{ "status": "user does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> |