Beruflich Dokumente
Kultur Dokumente
38
Password:
by Administrator
Login
Remember me
Ads by Google
[ Signup ]
[ Forgot password? ]
[ Resend Activation Email ]
Recommended
sites PHP Code Generator
PHP Tutorials
PHP 5 web hosting company
Craigs List Best code generator. Forms, Grids
Web Hosting Reviews
CodeConnect.net
Charts,Reports,Menus,Ajax support.
Web Design Toronto
JustHost Reviews
Logo design by Ars
www.scriptcase.net
PHP Hosting
In this tutorial I will show you how to create a PHP script to check whether the actual domain
name is available or not. In the next section I focus on the .com domains but you can extend
the script to handle as many top level domains as you want.
Step 1.
Let’s go through the basics. When you want to check whether a given domain name is
available or not you have to send a request to a whois server which maintains domain
registration details for the actual domain. In general all top level domain (usually just called
tld) has its own whois server. For example a whois server for .com domains is whois.crsnic.net
or for the .info domains it is whois.afilias.net. There can be more whois server for the actual tld.
To get information about the actual domain name we will send a request to the whois server
and then we will process the output. The output show us whether the domain is registered or
not.
Step 2.
After the short introduction let’s create some code. We will create a function which connects to
the whois server using socket connection. Download the response and analyze the output.
Analyzing the output means that we will looking for some special text which indicates whether
the domain is not found. If the response contains a text like “No match for” or “NOT FOUND”
than it means that the actual domain was not registered yet.
So our function will get 3 parameters:
1. Domain name
2. Whois server address
3. Not found text The complete code looks like this:
<?php
function checkDomain($domain,$server,$findText){
// Open a socket connection to the whois server
$con = fsockopen($server, 43);
if (!$con) return false;
1 of 3 15/02/2011 19:35
Creating a domain checker http://www.phptoys.com/e107_plugins/content/content.php?content.38
}
}
?>
Explanation:
The code is commented well but I try to explain it a little bit more detailed.
· As first step we try to connect to the whois server on port 43. If the connection fails than we
return to the main program.
· In case of established connection we will send the domain name to the server and read the
response in 128 bytes chunks.
· As we received the complete output then we close the connection. · Check whether the
requested string can be found in the response text. So we check if the string “No match for” is
there or not.
· If the string was found it means that the domain is not registered yet otherwise it is taken
already.
Step 3.
Now we have a function which can check a domain is available or not. To make a useful script
it would be nice to make a nice html page around it where a user can input the requested
domain and as result he/she get the availability. So let’s create a HTML page with a form which
contains an input field. Besides this I added a checkbox for the tld to make it easier to extend
the script. The HTML code with the built in form processing looks like this:
Explanation: The code is quite easy. The first part contains the HTML form code which as action
calls the script itself. There are 3 table rows. One for the domain name, one for the tld and one
the submit button. If the form was submitted – the POST array has the “submitBtn” in it – than
we set the domain name and the tld in 2 separate variables. After it we make a small check
whether the domain name is long enough. Here you can introduce more checks to avoid any
other not valid inputs. As next step the script begins to output a table with the result. Here a
function showDomainResult() is called which calls our main function and outputs result in a table
row. The code of the showDomainResult() function looks like this:
<?php
function showDomainResult($domain,$server,$findText){
if (checkDomain($domain,$server,$findText)){
echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
}
else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
}
?>
Step 4. Now we are ready. You have a basic script which can check a .com domain
availability. You can extend it with adding new checkboxes to the form for the new tlds and call
the showDomainResult() function with the new parameters. Finally here is the complete script:
<?php
function checkDomain($domain,$server,$findText){
// Open a socket connection to the whois server
$con = fsockopen($server, 43);
if (!$con) return false;
2 of 3 15/02/2011 19:35
Creating a domain checker http://www.phptoys.com/e107_plugins/content/content.php?content.38
while(!feof($con)) {
$response .= fgets($con,128);
}
function showDomainResult($domain,$server,$findText){
if (checkDomain($domain,$server,$findText)){
echo "<tr><td>$domain</td><td>AVAILABLE</td></tr>";
}
else echo "<tr><td>$domain</td><td>TAKEN</td></tr>";
}
?>
Tags:
Php Toys - 2006 - Php resources, scripts and tutorials - Privacy Policy
Insurance Index - Tutorial collection - Forex trading, brokers, reviews - Mortgage payment calculator
{THEMEDISCLAIMER}
Render time: 0.1904 sec, 0.0151 of that for queries. DB queries: 26.
3 of 3 15/02/2011 19:35