Advertisement
Guest User

Untitled

a guest
Oct 26th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. $shop = filter_input(INPUT_POST, "shop", FILTER_VALIDATE_INT);
  2. $item = filter_input(INPUT_POST, "item", FILTER_SANITIZE_SPECIAL_CHARS);
  3. $gold = filter_input(INPUT_POST, "gold", FILTER_VALIDATE_INT);
  4.  
  5. $itemData = json_decode($item);
  6.  
  7. $returnArray = [
  8. "success" => true,
  9. "message" => "oop",
  10. "gold" => $gold,
  11. "debug" => "work pls"
  12. ];
  13. $itemExists = false;
  14.  
  15. if ($shop == 0) {
  16. $filename = "Shop1.json";
  17. $fh = fopen($filename, "r");
  18. $content = fread($fh, filesize($filename));
  19. $content = json_decode($content, true);
  20. for ($i = 0; $i < count($content); $i++) {
  21. foreach ($content[$i] as $key => $value) {
  22. $content[$i][$key] = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
  23. }
  24. }
  25. fclose($fh);
  26.  
  27. $returnArray["gold"] = $gold + $itemData["price"];
  28. $returnArray["success"] = 'true';
  29. $returnArray["message"] = "Yeah, I can take that off your hands.";
  30.  
  31.  
  32. for ($i = 0; $i < count($content); $i++) {
  33. if ($content[$i]["id"] == $itemData["id"]) {
  34. $content[$i]["quantity"]++;
  35. $itemExists = true;
  36. }
  37. }
  38.  
  39. if (!$itemExists) {
  40. $itemData["quantity"] = 1;
  41. $itemData["price"] = $itemData["price"] * 2;
  42. array_push($content, $itemData);
  43. }
  44.  
  45.  
  46. $returnArray["debug"] = $content;
  47. $fh = fopen($filename, "w");
  48. fwrite($fh, json_encode($content));
  49. fclose($fh);
  50.  
  51. echo json_encode($returnArray);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement