Domain Name Checker in PHP with Source code

When we need to create a new website or a blog, we need a domain name but in the resent days almost all popular domain name are already registered. So first, we need to check the domain is available for registration or not. To do this first we visit the domain registrar website like Namecheap or GoDaddy to check domain name is available or not. After Check the domain name we register domain name.

But what if we develop our own domain name checker tool to check domain name is available or not and hosted in our own website. And facilitate our visitor to check domain name available or not. In this article we learn how to develop a domain name checker script. So, let’s begin.

domain name checker
technobush.com

Domain Name Checker Script in PHP


This is a small php script not hundred present accurate but work fine at medium level you can easily embed in your blog and business website. So your visitor easily search domain name is available to register or not.

HTML Part

First, open your code editor and create a domain-name-checker.php file. In this project we use bootstrap and jQuery. Include bootstrap and jQuery in head section .
After that create a container box to contain our small app. In the next step create a form with POST method, in the form create an input field to type domain name and dropdown to select popular TLD list. In this filed you can add almost any TLD domain extension you want.
And last create a Button to submit our POST method query to server and get result.

PHP Part

We need some variable so first we declare some variable like “ $name_domain” , “$godaddycheck”, “$namecomcheck”, and “$registercomcheck”.
$name_domain variable pass data from our input field to “$godaddycheck”, “$namecomcheck”, and “$registercomcheck” this variable go to destination URL and check the domain name is available or not and get data to see result on our app.

<!-- Author: Technobush (https://www.technobush.com) -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style type="text/css">
#domain-search-input{
padding: 3px;
border: solid 1px #E4E4E4;
border-radius: 6px;
background-color: #fff;
display: inline-block;
}
#domain-search-input input{
border: 0;
box-shadow: none;
}
.input-group[class*=col-] {
float: left;
width: auto;
}
.domain-box{display: grid; justify-content: center;
}
</style>
<div class="domain-box">
<h2>Check Domain Availability</h2>
<form action="" method=post>
<div id="domain-search-input">
<div class="input-group col-md-24" >
<input type="text" class="form-control" name="domain_name" placeholder="Domain Name">
</div>
<select name="suffix" class="btn btn-warning">
<option value=".com">.com</option>
<option value=".net">.net</option>
<option value=".org">.org</option>
<option value=".biz">.biz</option>
<option value=".info">.info</option>
<option value=".in">.in</option>
<option value=".us">.us</option>
<option value=".uk">.uk</option>
<option value=".au">.au</option>
<option value=".co">.co</option>
<option value=".gov">.gov</option>
<option value=".tech">.tech</option>
<option value=".online">.online</option>
<option value=".pro">.pro</option>
<option value=".io">.io</option>
<option value=".tv">.tv</option>
<option value=".live">.live</option>
<option value=".app">.app</option>
</select>
</div>
<input type="submit" class="btn btn-primary" name="check" value="Check">
</form>
<?php
if(isset($_POST['check'])) {
if (!empty($_POST['domain_name'])){
$name_domain = trim($_POST['domain_name']).$_POST['suffix'];
$godaddycheck = 'https://in.godaddy.com/domains/searchresults.aspx?checkAvail=1&tmskey=&domainToCheck='.$name_domain.'';
$namecomcheck = 'https://www.name.com/domain/search/'.$name_domain.'';
$registercomcheck = 'http://www.register.com/domain/search/wizard.rcmx?searchDomainName='.$name_domain.'&searchPath=Default&searchTlds=';
if ( gethostbyname($name_domain) != $name_domain ) {
echo "<H3 style='color:red;'>Domain $name_domain has taken.</H3>";
}else{
echo "<H3 style='color:green;' >Domain $name_domain is available.</H3>";
}
}
else {
echo "<H3 style='color:red;'>Error: Enter Domain Name.</H3>";
}
}
?>
</div>

PHP code Explanation

<?php
 
if(isset($_POST['check'])) {
 
 if (!empty($_POST['domain_name'])){
 $name_domain = trim($_POST['domain_name']).$_POST['suffix'];

	 $godaddycheck = 'https://in.godaddy.com/domains/searchresults.aspx?checkAvail=1&tmskey=&domainToCheck='.$name_domain.'';
	 $namecomcheck = 'https://www.name.com/domain/search/'.$name_domain.'';
	 $registercomcheck = 'http://www.register.com/domain/search/wizard.rcmx?searchDomainName='.$name_domain.'&searchPath=Default&searchTlds=';
 if ( gethostbyname($name_domain) != $name_domain ) {
 echo "<H3 style='color:red;'>Domain $name_domain has taken.</H3>";
 
 }else{
 echo "<H3 style='color:green;' >Domain $name_domain is available.</H3>";
 }
 }
 else {
 echo "<H3 style='color:red;'>Error: Enter Domain Name.</H3>";
 }
}
?>

if(isset($_POST[‘check’])) this line send post method to the server when button is click . Why we put “check” because in input type submit we add name is check you can see on in line 61.

if (!empty($_POST[‘domain_name’])) this line check domain_name is not empty “domain_name come from input type text on line 36”. if input type text in not empty send the post method.

After that create a variable $name_domain it hold the domain name what we enter in the input filed. trim($_POST[‘domain_name’]).$_POST[‘suffix’] it hold domain name with TLD extension we choose in dropdown.

$godaddycheck, $namecomcheck and $registercomcheck it hold the register URL to check the domain name without going to the registrar website and get the result.

if ( gethostbyname($name_domain) != $name_domain ) if domain match with the result means domain name is not available, if domain name is not match with the result means domain is available to register.

Final Word

If you have any question or feedback regarding this script please comment on the comment box. I hove this article helpful. Subscribe our Newsletter to notify article like this.

Also Read

I've loved ❤ technology and always curious about new tech innovation. I've been a technology writer and passionate blogger for last 3 year and write How to guide to help people become a tech-savvy.

2 thoughts on “Domain Name Checker in PHP with Source code”

Leave a Comment