<?php
$curl = curl_init();
$phone = $_GET['phone'] ?? '';
if ($phone != '' && strlen($phone) == 10) {
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://www.dncscrub.com/app/main/rpc/scrub?phoneList=' . $phone . '&version=5&output=json',
        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(
            'loginId: 010E969C27A85E8FC3F5F107B1487433C66983BB61E0'
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    $jsonRes = json_decode($response, true);
    // print_r($jsonRes);
    $status = $jsonRes[0]['ResultCode'];
    $DNC = ['D', 'P', 'O', 'X'];
    echo (in_array($status, $DNC) || $jsonRes[0]['DoNotCallToday'] == "1") ? 1 : 0;
} else {
    echo 1;
}
