RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

Simple WHOIS Lookup With PHP

Simple WHOIS Lookup With PHP

WHOIS is a protocol that is widely used for querying server databases in order to determine the registrant or assignee of a domain name or IP address (range). In its simplest form, building a small PHP script to query the appropriate WHOIS server and outputting readable information is quite simple, yet complex solutions are usually required to extract full functionality from the WHOIS system.

This code was first posted to martinetics over 10 years ago before it was migrated to Internoetics in 2009. Since then, it's seen tens of thousands of downloads, and it's even been referenced in a few text books. You'll now see the crappy code copied all over the web.

Included in the download below is a very simple yet featured script to output the registrant of a domain name stored in WHOIS records. There's little security, and the code doesn't do much other than check the registrant. The code can be quickly modified (via the config file) into a turnkey-style website. You can see a copy of the example code in action here.

Simple WHOIS Lookup With PHP

Download code for a working website example

While the code was written in the same time it takes most people to brush their teeth, there are a few features:

  • Config file to alter text. Find it in custom/config.inc.php.
  • Some validation is performed on the input.
  • Automatically checks for updates.
  • Social integration.
  • You may optionally use a simple captcha.
  • Data will be cached as per your defined cache period. We use the Simple Cache code. Define your cache directory in your config.inc.php file.
  • The code is basic. Since we expect to improve the code and add a few features, ensure BELIEFMEDIA_CHECK_UPDATES is set to TRUE in custom/config.inc.php. A notice will be displayed, and the script will send you an email when an update is available.

The code is an example, not a solution. However, it'll be developed into something aesthetically pleasing over time (update notifications are automated). Modify the custom/config.inc.php file with the required information to enable the website. Updates will generally leave the custom directory alone.

PHP Code

In its simplest form, the request to a WHOIS server is as per the below example. The full list of WHOIS servers for each domain extension is included in the download.

1
<?php 
2
/*
3
 Simple WHOIS Lookup With PHP
4
 http://www.beliefmedia.com/simple-php-whois
5
*/
6
 
7
function beliefmedia_whois_query($domain, $server) {
8
 
9
   /* connect to whois server */
10
   if ($conn = fsockopen ($server, 43)) {
11
     fputs($conn, $domain . &quot;\r\n&quot;);
12
 
13
     while(!feof($conn)) {
14
       $output .= fgets($conn,128);
15
     }
16
 
17
     fclose($conn);
18
     $return = nl2br($output);
19
   }
20
 
21
 return $return;
22
}
23
 
24
/* Usage */
25
$domain = 'beliefmedia.com';
26
$server = 'whois.crsnic.net';
27
echo beliefmedia_whois_query($domain, $server);

Considerations

  • WHOIS information on Wikipedia
  • Delegation details of top-level domains (iana.org)
  • We're in the process of rebuilding the entire WHOIS server database. If you find an error or addition, please let us know.

Video Introduction

Download


Title: Simple WHOIS Lookup With PHP
Description: Simple WHOIS Lookup With PHP. Download includes full sample website.
  Download • Version 0.2, 832.2K, zip, Category: PHP Code & Snippets

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment