council_lookup.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // council_lookup.php
  3. header('Content-Type: application/json; charset=utf-8');
  4. try {
  5. // Expect town, postcode, state = TAS
  6. $town = isset($_GET['town']) ? trim($_GET['town']) : '';
  7. $postcode = isset($_GET['postcode']) ? trim($_GET['postcode']) : '';
  8. $state = isset($_GET['state']) ? strtoupper(trim($_GET['state'])) : '';
  9. if ($town === '' || $postcode === '' || $state !== 'TAS') {
  10. echo json_encode(['ok' => false, 'reason' => 'missing or invalid params']);
  11. exit;
  12. }
  13. // Load your data file that defines $councils
  14. // Change this path to where your 743 line file lives
  15. require __DIR__ . '/councils_tas.php'; // defines $councils = array(...)
  16. $needleTown = mb_strtolower($town);
  17. $needlePC = $postcode;
  18. $found = null;
  19. foreach ($councils as $row) {
  20. // Defensive checks
  21. if (!isset($row['town'], $row['postcode'])) continue;
  22. if (mb_strtolower($row['town']) === $needleTown && (string)$row['postcode'] === (string)$needlePC) {
  23. $found = [
  24. 'council' => $row['council'] ?? '',
  25. 'shapeFile' => $row['shapeFile'] ?? ''
  26. ];
  27. break;
  28. }
  29. }
  30. if ($found) {
  31. echo json_encode(['ok' => true] + $found);
  32. } else {
  33. echo json_encode(['ok' => false, 'reason' => 'not found']);
  34. }
  35. } catch (Throwable $e) {
  36. http_response_code(500);
  37. echo json_encode(['ok' => false, 'reason' => 'server error']);
  38. }