From 423c37e0254a0f7a5b4ef5326da4379b7c65792d Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Tue, 29 Jul 2025 21:29:50 +0200 Subject: contirb api added api that returns a specific users contributed clicks and their team --- README.md | 1 - backend/contrib.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 backend/contrib.php diff --git a/README.md b/README.md index 0e2e88b..704888b 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,6 @@ curl -X POST -d '{ "key": "value" }' http://localhost:8000/yourapifile.php ### Backend -- add api that returns a specific users clicks - add name and password change - add anonymous clicking for a team diff --git a/backend/contrib.php b/backend/contrib.php new file mode 100644 index 0000000..47538da --- /dev/null +++ b/backend/contrib.php @@ -0,0 +1,47 @@ + + * 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 = [ "name" ]; +$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["name"]) || trim($wrkarr["name"]) == ""): + die('{ "status": "name was not provided.\nuse the rank api if you want to see all users or the index api if you want to see all teams." }'); +else: + + $query = $pdo->prepare("SELECT name, team, clicks FROM users WHERE name LIKE ?"); + $query -> execute([$wrkarr["name"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + die("{ \"status\": \"success\", \"team\": \"$found[team]\", \"clicks\": \"$found[clicks]\" }"); + + else: + die('{ "status": "name does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> -- cgit v1.2.3