Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $shop = filter_input(INPUT_POST, "shop", FILTER_VALIDATE_INT);
- $item = filter_input(INPUT_POST, "item", FILTER_SANITIZE_SPECIAL_CHARS);
- $gold = filter_input(INPUT_POST, "gold", FILTER_VALIDATE_INT);
- $itemData = json_decode($item);
- $returnArray = [
- "success" => true,
- "message" => "oop",
- "gold" => $gold,
- "debug" => "work pls"
- ];
- $itemExists = false;
- if ($shop == 0) {
- $filename = "Shop1.json";
- $fh = fopen($filename, "r");
- $content = fread($fh, filesize($filename));
- $content = json_decode($content, true);
- for ($i = 0; $i < count($content); $i++) {
- foreach ($content[$i] as $key => $value) {
- $content[$i][$key] = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
- }
- }
- fclose($fh);
- $returnArray["gold"] = $gold + $itemData["price"];
- $returnArray["success"] = 'true';
- $returnArray["message"] = "Yeah, I can take that off your hands.";
- for ($i = 0; $i < count($content); $i++) {
- if ($content[$i]["id"] == $itemData["id"]) {
- $content[$i]["quantity"]++;
- $itemExists = true;
- }
- }
- if (!$itemExists) {
- $itemData["quantity"] = 1;
- $itemData["price"] = $itemData["price"] * 2;
- array_push($content, $itemData);
- }
- $returnArray["debug"] = $content;
- $fh = fopen($filename, "w");
- fwrite($fh, json_encode($content));
- fclose($fh);
- echo json_encode($returnArray);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement