How to Find Whois information for a domain using PHP

Authors: CodeToday | PHP Code | Views: 67 | Posted: 08 AM: 09/30/2017

To see information about a certain domain you can go to sites like,, ..., but information is generally aggregated. Today I will guide you how to get domain information about your website in a selective way using PHP code. 

The domain name information you get here is only the Registrar URL, Updated Date, Creation Date, Registry Expiry Date, Name Server, you can get more if you want using the same preg_match function.

Bootstrap Library

<link rel="stylesheet" href="">
Information Source about the domain is taken from through the following function:

function whois($domain){
$whois = '';
$connection = @fsockopen('', 43);
if ($connection) {
    @fputs($connection, $domain ."
    while (!feof($connection)) {
        $whois .= @fgets($connection, 128);
return $whois;


<form action="" method="post" class="form-inline">
<div class="form-group">
<input type="text" name="domain" value="<?=$_POST['domain']?>" size="80" class="form-control" placeholder = "Enter domain here ..." required/>
<div class="form-group">
<button class="btn btn-info" type="submit" name="submit"><i class="glyphicon glyphicon-search"></i> Find Whois Now</button>

PHP Source Code

if(isset($_POST['submit'])) {
	$domain   = trim($_POST['domain']);
	$data = whois($domain);
	//echo '<pre>'.$data.'</pre>';
	preg_match('/Registrar URL: (.*)/', $data, $RegistrarURL);
	preg_match('/Updated Date: (.*)/', $data, $UpdatedDate);
	preg_match('/Creation Date: (.*)/', $data, $CreationDate);
	preg_match('/Registry Expiry Date: (.*)/', $data, $RegistryExpiryDate);
	preg_match_all('/Name Server: (.*)/', $data, $NameServer);
	echo '<div class="list-group">';
	echo '<h3 class="list-group-item active">Find Whois information for '.$domain.'</h3>';
    echo '<span class="list-group-item">Registrar URL: '.$RegistrarURL[1].'</span>';
	echo '<span class="list-group-item">Updated Date: '.$UpdatedDate[1].'</span>';
	echo '<span class="list-group-item">Creation Date: '.$CreationDate[1].'</span>';
	echo '<span class="list-group-item">Registry Expiry Date: '.$RegistryExpiryDate[1].'</span>';
	echo '<span class="list-group-item">Name Server: '.implode(",",$NameServer[1]).'</span>';	
	echo '</div>';

You can view the resulting image below after completing the above steps:

How to Find Whois information for a domain using PHP

If you have any questions, please leave a message below