getTwitch.php 1013 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. include_once('includes/db_connect.php');
  3. include_once('includes/global_functions.php');
  4. $radioid = $_GET['radioid'];
  5. $radiomac = $_GET['radiomac'];
  6. if($radioid == "" && $radiomac == ""){
  7. print(json_encode([error => "Not a valid radioid"]));
  8. die();
  9. }else{
  10. if($radiomac != ""){
  11. $radiomac = str_replace(':', '', $radiomac);
  12. $radioid = substr($radiomac, 6 , 11);
  13. }
  14. $array = array();
  15. if($stmt = $mysqli -> prepare("SELECT username FROM Twitch LEFT JOIN users ON Twitch.uid = users.uid WHERE users.radiotoken = ?")){
  16. $stmt -> bind_param("s", $radioid);
  17. $stmt -> execute();
  18. $stmt -> bind_result($TwitchUsername);
  19. while($result = $stmt -> fetch()){
  20. array_push($array, array( username =>$TwitchUsername)
  21. );
  22. };
  23. $stmt -> close();
  24. }
  25. print(json_encode($array, JSON_UNESCAPED_SLASHES));
  26. }