#native_company# #native_desc#
#native_cta#

*KNOW* when that domain will expire … with PHP!

By Kevin Kinsey
on November 24, 2003

As a web programmer, host, or consultant, in time you’ll probably become “responsible” for a number of domains.

I recently “lost” a domain that I’d inherited from another consultant, because I’d never been added to the “whois” records as the technical contact. (AAMOF, the “tech”, “billing” and “admin” contacts were *all* deprecated — so no one was notified!)

We generally register all our domains with the same registrar, and get email when expirations are imminent. However, a few domains have been ‘inherited’ and we don’t receive much from them. Rather than spend a lot of time entering our information at every registrar’s site, we just hacked together a short PHP script that we can call at any time from a desktop (‘Nix) machine and view regularly to see when all those troublesome registrations will come due again.

Assumptions:

1. you can connect to a database (ours is MySQL)

2. your database has a table (‘domains’) simply listing the domains you’re responsible for

3. the biggie — you’ve given shell access to your webserver (which means this isn’t to be placed on a production machine [for security reasons]). You could, however, easily modify this for the PHP CLI and use it in almost any environment.

<?php

include 'header.html';  // nothing special, for appearance

ini_set('max_execution_time', '360'); // vary according to # of domains
db_conn();  // our function handles the connection, pw, and db selection
// it's included via the header file, above
$domains=array();
$sql="select * from domains order by name";
$result=mysql_query($sql);

if ($result) {
                while ($row=mysql_fetch_array($result)) {
                        $domain=$row[0];
                        $data=ucfirst(shell_exec("whois $domain | grep xpir"));
// grepping 'xpir' will get "Expiration, expiration, expires, Expires" etc.
// should work with most whois services

// do away with a irksome "NOTICE" message
// that appears in some of our "WHOIS" entries
// and adds two lines or more to the output...

                        if ($notice=strstr($data, 'NOTICE')) {  
                                $newdata=explode('NOTICE', $data);
                                $data=$newdata[0];
                        }
                        echo "
<font size=2>Domain: $domain --- $data</font>
"; } include 'footer.html'; // again, plain HTML output } else { include 'header.html'; echo "

Check database engine and/or Internet connection --- query(ies) failed.

"; include 'footer.html'; } ?>

Simple, eh?

Some Extensions:

a] highlight soon-to-expire entries in some way…

b] have the script send mail to an appropriate person, or your billing department/service, etc…

c] port it to Windows :p

d] this could probably be done with sockets (instead of shell) to eliminate the security risk on production servers

e] Go nuts! Have the script parse the billing and admin contacts, and send ’em an automagic email notice with attached invoice via pdflib….