Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved isAvailable #51

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5fd219e
Fixed .id whois servers
tsiedsma Dec 10, 2015
00090cf
Updated unitedtld.com to rightside.co
tsiedsma Dec 11, 2015
6a31624
not_found_string as array for multiple options,
Feb 24, 2016
1afa064
Replace whois.nic.ad.jp with whois.jprs.jp
malkusch Mar 9, 2016
1c2d2c5
Remove wrong mappings for whois.co.za
malkusch Mar 10, 2016
fc46fb9
Fix pattern for co.ac
malkusch Mar 10, 2016
6d1a620
Fix pattern for com.ua
malkusch Mar 10, 2016
85b7965
Remove wrong mapping for gov.mx
malkusch Mar 10, 2016
8d33c0b
Remove wrong mapping for mil.tr
malkusch Mar 10, 2016
02bbd7d
Remove wrong mapping for edu.cn
malkusch Mar 10, 2016
672c5cc
Fix pattern for whois.net.ua
malkusch Mar 10, 2016
46eb930
Fix pattern for ac.ke
malkusch Mar 10, 2016
0251b82
Fix pattern for whois.nic.or.kr
malkusch Mar 10, 2016
3b10f3c
Typo in comment
alsopub Mar 18, 2016
413c361
Update whois.servers.json
marcelod Mar 24, 2016
51a4f0b
Proxy for cURl
flashbag Apr 12, 2016
2b7121a
Merge branch 'master' of https://github.com/whois-server-list/php-whois
igormino104 Apr 21, 2016
4d5918d
Merge branch 'master' of https://github.com/lhdev/php-whois
igormino104 Apr 21, 2016
805685e
Merge branch 'master' of https://github.com/marcelod/php-whois
igormino104 Apr 21, 2016
62880f0
Merge branch 'master' of https://github.com/alsopub/php-whois
igormino104 Apr 21, 2016
8fd3cf6
Merge branch 'master' of https://github.com/flashbag/php-whois
igormino104 Apr 21, 2016
9941041
fixed match pattern for co.uk
igormino104 Apr 21, 2016
b21a5c4
Merge branch 'master' of https://github.com/regru/php-whois
igormino104 Nov 10, 2016
307baba
added method of check whether server for TLD is defined
igormino104 Nov 10, 2016
57622aa
added check for exist WHOIS server
igorplaton Jul 31, 2018
07c69b1
added parameters errno, errstr and timeout for fsockopen
igormino104 Sep 3, 2020
5b9e4b5
Merge branch 'regru:master' into master
igorplaton Sep 11, 2024
b860d23
removed "UNMAINTAINED"
igorplaton Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/usage-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
include '../src/Phois/Whois/Whois.php';

$sld = 'reg.ru';
//$sld = 'com.sk'; // Not found. The Domain cannot be registered

$domain = new Phois\Whois\Whois($sld);

Expand Down
82 changes: 54 additions & 28 deletions src/Phois/Whois/Whois.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Whois
/**
* @param string $domain full domain name (without trailing dot)
*/
public function __construct($domain)
public function __construct($domain, $proxy = false)
{
$this->domain = $domain;
// check $domain syntax and split full domain name on subdomain and TLDs
Expand All @@ -25,6 +25,9 @@ public function __construct($domain)
) {
$this->subDomain = $matches[1];
$this->TLDs = $matches[2];
if ($proxy) {
$this->proxy = $proxy;
}
} else
throw new \InvalidArgumentException("Invalid $domain syntax");
// setup whois servers array from json file
Expand All @@ -39,7 +42,7 @@ public function info()
// If TLDs have been found
if ($whois_server != '') {

// if whois server serve replay over HTTP protocol instead of WHOIS protocol
// if whois server serve reply over HTTP protocol instead of WHOIS protocol
if (preg_match("/^https?:\/\//i", $whois_server)) {

// curl session to get whois reposnse
Expand All @@ -52,6 +55,11 @@ public function info()
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, $proxy['ip']);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy['port']);
}

$data = curl_exec($ch);

if (curl_error($ch)) {
Expand Down Expand Up @@ -154,32 +162,45 @@ public function getSubDomain()
return $this->subDomain;
}

public function isAvailable()
{
$whois_string = $this->info();
$not_found_string = '';
if (isset($this->servers[$this->TLDs][1])) {
$not_found_string = $this->servers[$this->TLDs][1];
}

$whois_string2 = @preg_replace('/' . $this->domain . '/', '', $whois_string);
$whois_string = @preg_replace("/\s+/", ' ', $whois_string);

$array = explode (":", $not_found_string);
if ($array[0] == "MAXCHARS") {
if (strlen($whois_string2) <= $array[1]) {
return true;
} else {
return false;
}
} else {
if (preg_match("/" . $not_found_string . "/i", $whois_string)) {
return true;
} else {
return false;
}
}
}
public function isAvailable()
{
$whois_string = $this->info();
$not_found_string = '';
if (isset($this->servers[$this->TLDs][1])) {
$not_found_strings = array_slice($this->servers[$this->TLDs], 1);
}

$whois_string2 = @preg_replace('/' . $this->domain . '/', '', $whois_string);
$whois_string = @preg_replace("/\s+/", ' ', $whois_string);

$return = true;

if (is_array($not_found_strings)) {
foreach ($not_found_strings as $not_found_string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to respect the original codestyle when you're making a PR.

$array = explode (":", $not_found_string);
if ($array[0] == "MAXCHARS") {
if (strlen($whois_string2) <= $array[1]) {
$return &= true;
} else {
$return &= false;
}
} else if ($array[0] == "NEGATION") {
if (preg_match("/" . $array[1] . "/i", $whois_string)) {
$return &= false;
} else {
$return &= true;
}
} else {
if (preg_match("/" . $not_found_string . "/i", $whois_string)) {
$return &= true;
} else {
$return &= false;
}
}
}
}
return $return;
}

public function isValid()
{
Expand All @@ -198,4 +219,9 @@ public function isValid()

return false;
}

public function isServerDefined() {
return isset($this->servers[$this->TLDs]);
}

}
Loading