SiteโฏBuilder
Editing:
api.php
writable 0666
<?php // api.php (place in /coupon/api.php) header('Content-Type: application/json'); $root = dirname(__DIR__); $ph = preg_replace('/\D/', '', $_GET['ph'] ?? $_POST['ph'] ?? ''); $bizdir = $root . '/ph/' . $ph; $bizjson = "$bizdir/business.json"; $couponjson = "$bizdir/coupon.json"; $isPaid = is_readable($bizjson); if (!$ph || !is_dir($bizdir)) { http_response_code(400); echo json_encode(['error' => 'Business not found.']); exit; } if (!$isPaid) { http_response_code(403); echo json_encode(['error' => 'Not a paid member.']); exit; } if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (is_readable($couponjson)) { $coupon = json_decode(file_get_contents($couponjson), true) ?: []; } else { $coupon = []; } echo json_encode(['success' => true, 'coupon' => $coupon]); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $data = json_decode(file_get_contents("php://input"), true); $coupon = [ 'title' => trim($data['title'] ?? ''), 'desc' => trim($data['desc'] ?? ''), 'code' => trim($data['code'] ?? ''), 'expiry' => trim($data['expiry'] ?? ''), ]; file_put_contents($couponjson, json_encode($coupon, JSON_PRETTY_PRINT)); echo json_encode(['success' => true, 'coupon' => $coupon]); exit; }
Save changes
Create folder
writable 0777
Create
Cancel