Repository navigation
Expand file tree
/
Copy pathDomainApi.php
More file actions
77 lines (62 loc) · 2.21 KB
/
Copy pathDomainApi.php
File metadata and controls
77 lines (62 loc) · 2.21 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
class lawshost {
function check_availability ($domain, $tld) {
$arguments = array(
'service' => 'whois',
'domain-name' => $domain,
'tld' => $tld
);
$result = $this->_makeGetRequest('/domains', $arguments);
return $result;
}
function get_tlds () {
$arguments = array(
'service' => 'gettlds'
);
$result = $this->_makeGetRequest('/domains', $arguments);
return $result;
}
function _makeGetRequest($servlet, $arguments)
{
return $this->_makeRequest($servlet, $arguments, false);
}
function _makeRequest($servlet, $arguments, $isPost = false)
{
$arguments['apikey'] = "<ENTER YOUR API KEY>";
$request = 'https://api.laws-hosting.co.uk';
$request .= $servlet . '.php';
$data = '';
foreach ($arguments as $name => $value) {
$name = urlencode($name);
if (is_array($value)) {
// Need to handle arrays
foreach ($value as $multivalue) {
if ($multivalue === true) $multivalue = 'true';
else if ($multivalue === false) $multivalue = 'false';
$data .= $name . '=' . urlencode($multivalue) . '&';
}
} else {
if ($value === true) $value = 'true';
else if ($value === false) $value = 'false';
$data .= $name . '=' . urlencode($value) . '&';
}
}
$request .= '?' . $data;
$requestType = 'GET';
$response = $this->_curl($request, $requestType);
return json_decode($response);
}
function _curl ($request, $requestType) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// important to supply an user agent as I block empty ones
$agent = 'Mozilla/5.0 (compatible; https://www.laws-hosting.co.uk)';
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$contents = curl_exec ($ch);
curl_close ($ch);
return $contents;
}
}
?>