diff options
author | hitlerrip <git@hitler.rip> | 2025-08-02 22:29:54 +0200 |
---|---|---|
committer | hitlerrip <git@hitler.rip> | 2025-08-02 22:29:54 +0200 |
commit | 67c3af8f8c9bd363f78fcce0c9d08958503918af (patch) | |
tree | 2ca3120b49bfc089fb77d5251301bf0a525d51b0 | |
parent | 6b3e92478de8225ac1d2db9deb448c65d4732fca (diff) | |
download | hitler-clicker-67c3af8f8c9bd363f78fcce0c9d08958503918af.tar.gz hitler-clicker-67c3af8f8c9bd363f78fcce0c9d08958503918af.tar.bz2 hitler-clicker-67c3af8f8c9bd363f78fcce0c9d08958503918af.zip |
anon clicks
added api for anonymous clicks
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | backend/anon.php | 62 | ||||
-rw-r--r-- | backend/index.php | 2 |
3 files changed, 63 insertions, 2 deletions
@@ -42,7 +42,6 @@ curl -X POST -d '{ "key": "value" }' http://localhost:8000/yourapifile.php ### Backend - add name and password change -- add anonymous clicking for a team ### Frontend diff --git a/backend/anon.php b/backend/anon.php new file mode 100644 index 0000000..c6c148d --- /dev/null +++ b/backend/anon.php @@ -0,0 +1,62 @@ +<?php +/* hitler-clicker + * api for anonymously incrementing counters + * © 2025 hitler.rip <git@hitler.rip> + * licensed under AGPLv3-or-later; see LICENSE.md for more information + */ + +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 = [ "team" ]; +$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["team"]) || trim($wrkarr["team"]) == ""): + die('{ "status": "team was not provided.\ncould not add a click." }'); +else: + + $query = $pdo->prepare("SELECT team FROM stats WHERE team LIKE ?"); + $query->execute([$wrkarr["team"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + $query = $pdo->prepare("SELECT team, clicks, fromanon FROM stats WHERE team LIKE ?"); + $query->execute([$found["team"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + + $newteamclicks = $found["clicks"] + 1; + $newanonclicks = $found["fromanon"] + 1; + + $query = $pdo->prepare("UPDATE stats SET clicks = :clicks , fromanon = :fromanon WHERE stats.team = :team"); + $query->execute([ + "clicks" => "$newteamclicks", + "fromanon" => "$newanonclicks", + "team" => "$found[team]", + ]); + + die("{ \"status\": \"success\", \"nac\": \"$newanonclicks\" \"ntc\": \"$newteamclicks\" }"); + + + else: + die('{ "status": "team does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> diff --git a/backend/index.php b/backend/index.php index 844e0f8..7de8d0a 100644 --- a/backend/index.php +++ b/backend/index.php @@ -15,11 +15,11 @@ try { }; /* -*/ $query = $pdo->prepare("DROP TABLE `hitlerclicker`.`stats`"); $query->execute(); $query = $pdo->prepare("DROP TABLE `hitlerclicker`.`users`"); $query->execute(); +*/ $query = $pdo->prepare("CREATE TABLE IF NOT EXISTS `hitlerclicker`.`stats` ( `team` VARCHAR(256) NOT NULL DEFAULT uuid() , `clicks` INT(128) unsigned NOT NULL DEFAULT '0' , `fromanon` INT(128) unsigned NOT NULL DEFAULT '0' , PRIMARY KEY (`team`) ) ENGINE = InnoDB;"); $query->execute(); |