How to Find WHOIS Information for a Domain in PHP
The below code will allow you to quickly return a full WHOIS record (including registration details, domain owner info, etc.) for any input domain name — including a validation check to ensure the domain exists in the first place.
Just run the following command to install the client SDK:
composer require cloudmersive/cloudmersive_validate_api_client
Then copy & paste from the code examples below to structure your API call:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\DomainApi(
new GuzzleHttp\Client(),
$config
);
$domain = "domain_example"; // string | Domain name to check, for example \"cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.
try {
$result = $apiInstance->domainPost($domain);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DomainApi->domainPost: ', $e->getMessage(), PHP_EOL;
}
?>
To authenticate each request for free, register a free account on the Cloudmersive website — this will provide you with a free-tier API key & a limit of 800 API calls per month (there are zero commitments once you reach that limit; you can upgrade to an enterprise any time if need be).
That’s all there is to it — now you have an easy WHOIS domain service you can count on.