-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-domain-availability.php
41 lines (36 loc) · 1.17 KB
/
check-domain-availability.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
function isDomainAvailable($domain){
$client = new Client();
$env = parse_ini_file('.env');
try{
$qry = [
'credits' => 'DA',
'domainName' => $domain,
'apikey' => $env['whoisxml_api_key']
];
//get a long-lived User access token
$response = $client->request('GET', "https://domain-availability.whoisxmlapi.com/api/v1"
, ['query' => $qry]);
$body = $response->getBody();
$data = json_decode($body->getContents());
if(!isset($data->DomainInfo->domainAvailability) || $data->DomainInfo->domainAvailability=="UNAVAILABLE"){
return false;
}
else{
return true;
}
}
catch (\GuzzleHttp\Exception\RequestException $e){
if ($e->hasResponse()) {
$response = $e->getResponse();
var_dump($response->getReasonPhrase()); // Response message;
var_dump(json_decode((string) $response->getBody())); // Body as the decoded JSON;
}
else{
var_dump($e->getMessage());
}
}
}
?>