1){ $id = $query[0]; } else{ // Id is mandatory, a list can be retrieved header("HTTP/1.1 403 A list of profiles cant be retrieved. Please specify a profile ID or player name."); syslog(LOG_INFO, "[APIv1] HTTP/1.1 403 A list of profiles cant be retrieved. Please specify a profile ID or player name."); return 403; } // Get player $statement = $db->prepare(" SELECT user.api_key AS api_key, player.id AS id, player.public AS public FROM user, player WHERE user.id = player.user AND player.id = :id AND user.api_key = :api_key; "); $statement->bindValue(":id", $id, SQLITE3_INTEGER); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r == null){ // No player found header("HTTP/1.1 404 Player not found."); syslog(LOG_INFO, "[APIv1] HTTP/1.1 404 Player not found."); return 403; } if ($r["public"] != 1 && $r["key"] != filter_input(INPUT_GET, "key")){ header("HTTP/1.1 403 The profile is not public."); syslog(LOG_INFO, "[APIv1] HTTP/1.1 403 The profile is not public."); return 403; } // Permission granted, get player data. $player_id = $r["player_id"]; $player = new Player($player_id); // Build array // TODO: Add way more data $player = [ "username" => $player->name, "level" => $player->level, "public" => $player->public ]; echo(json_encode($player)); header("HTTP/1.1 200 Success."); syslog(LOG_INFO, "[APIv1] HTTP/1.1 200 Success."); return 200; } catch(Exception $e) { header("HTTP/1.1 500 Unexpeced error: " . $e->getMessage()); syslog(LOG_ERR, "[APIv1] HTTP/1.1 500 Unexpected error: " . $e->getMessage()); return 500; } ?>