-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-address.php
52 lines (44 loc) · 1.38 KB
/
validate-address.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once "db.php";
$street = $_REQUEST['street'];
$street2 = $_REQUEST['street2'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zipcode = $_REQUEST['zipcode'];
$url = USPS_BASE_URL . "" . USPS_API . "?auth-id=" . USPS_AUTH_ID . "&auth-token=" . USPS_AUTH_TOKEN . "&license=" . USPS_LICENSE . "&candidates=" . USPS_CANDIDATES . "&match=" . USPS_MATCH;
$query_string = "&street=" . urlencode($street) . "&street2=" . urlencode($street2) . "&city=" . urlencode($city) . "&state=" . urlencode($state) . "&zipcode=" . urlencode($zipcode);
$apiurl = $url . "" . $query_string;
$curl = curl_init();
curl_setopt_array($curl, array(
// CURLOPT_URL => $urls,
CURLOPT_URL => $apiurl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'content-type: application/json'
),
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
$result = [
"success" => false,
"message" => "Server error"
];
echo json_encode($result);
die;
}
curl_close($curl);
$result = [
"success" => true,
"message" => "Success",
"data" => json_decode($response)
];
echo json_encode($result);
die;
?>