Using Sam’s Whois

The file samswhois.inc.php provides an easy way to use the samswhois.class.php class. Using it, you can install a basic whois lookup with just one line of code:

A Simple Example

The code above will display the following form and handle all processing and display of the whois lookup:

Setting Options

Most of the options for Sams Whois can be set by setting various variables in the script above before the line that includes samswhois.inc.php.

For example, the following code turns on caching, turns on the use of a secure code image, limits the tlds supported to com, net and org, and displays a drop-down select box for the user to choose the tld from:

This code will result in a form like this and will handle all aspects of checking the secure code, looking up the domain and displaying the result:

As you can see above, customizing the options is a simple process. The following options are available for customization:

Tld Related Options

Set the following variables to alter which tlds are available and whether or not they are displayed:

Caching Options

Sams Whois has built-in support for caching whois lookup results so that the next time the domain is looked-up these results can be used instead of re-querying the whois servers.

This reduces the amount of work the script has to do, speeding it up. It is recommended that you do not cache results for more than 24 hours.

To use caching, you need to set the permissions of the “samswhois/cache” folder so that the script can create files in it. You may also need to delete the files in this folder from time to time.

Secure Code Options

The secure code option displays a random 4-digit code to the user as an image, and asks them to enter it when they perform a whois lookup.

This serves as a deterrent to people who might otherwise abuse the service by using automated scripts to check 100s or 1000s of domains per minute, usually to extract email addresses to use for spamming. As an excessive amount of queries can result in your i.p. address being banned by the whois servers, stopping this type of activity is in your interest.

This option requires the gd image library which is installed by default on most php distributions. Contact your hosting company if you are unsure if it is installed.

It requires that the file “swsecureimage.php” (included in the samswhois distribution) is uploaded to your server. This file outputs the image. To use the secure code option you must call the function session_start() at the top of your page, and set the $swSecure variable as illustrated below:

You must ensure sure that the $m_font variable in the “/samswhois/secureimagecode.class.php” is set to the name of a .ttf font stored in the same folder. By default this should already be set up correctly.

Options (font, size, number of characters, and whether or not to use lower and upperĀ case characters) can be set by editing the variables at the top of the “/samswhois/secureimage.class.php” file.

Messages

Most of the default messages displayed by the script can be overridden by setting themĀ in your script before including the samswhois.inc.php file. The following messages can be set:

Whois Data Processing / Display Options

There are several additional options you can set that affect the whois data that is displayed to the user.

The “clean” option removes extraneous text from the whois results (for example, whois server terms of use) resulting in a clearer presentation of the result to your users.

The “hilight” option hilights certain fields in the result such as expiration date and registrant name, again resulting in clearer presentation of the results.

Both these options depend on configuration settings in the config.txt file being set for the whois server used for the lookup. You can set the script to never use these options, always use these options, or present the user with checkboxes to choose whether or not to clean or hilight the whois result.

Authoratitive Whois Server Options

Finally, you can tell the script whether or not to check the authoratitive whois server for certain tlds (notably com and net). The default, registry whois data for these tlds only contains basic whois information, as well as the address of the registrar’s whois server for full information.

By default the script redirects to the authoratitive server, but you can turn this option off. You can also set whether the script displays both sets of whois data (default), or just the authoratitive one.

For information on changing the design of the lookup form and results, see the css styles documentation, or the code in the samswhois.inc.php file.