-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
35 lines (26 loc) · 780 Bytes
/
index.php
File metadata and controls
35 lines (26 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
function debug_to_console($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('Debug Objects: " . $output . "' );</script>";
}
$input = $_POST["search"] ?? null;
if (empty($_ENV['API_KEY'])) {
die('Please enter an API Key.');
}
$district = null;
if ($input) {
$geocoder = new Geocodio\Geocodio();
$geocoder->setApiKey($_ENV['API_KEY']);
try {
$output = $geocoder->geocode($input, ['cd']);
$district = $output->results[0]->fields->congressional_districts[0] ?? null;
} catch(Exception) {
$district = null;
}
}
require 'index.view.php';