Quick and Easy PHP WHOIS Script

I like to be able to type “whois somedomain.com” in my browser and have it bring up the WHOIS information. The site I’ve been using has a captcha (annoying) and has gotten unreliable, so I wrote this quick and easy script to pull the full unformatted WHOIS data for me:

<?php $d =  isset($_GET['d']) ? $_GET['d'] : ''; ?>
<title>WHOIS <?php echo $d; ?></title>
    exec("whois ".escapeshellarg($d), $results);


    $server = '';

    foreach($results as $result){
        if(stripos($result, 'whois server:')){
            $server = trim(str_replace('whois server:','',strtolower($result)));

        passthru("whois -h ".escapeshellarg($server)." ".escapeshellarg($d));
        foreach($results as $result){
            echo $result.PHP_EOL;


This script should work out-of-the-box for most Linux installations.

You can make the “whois somedomain.com” functionality work in Firefox by creating a bookmark with a location of: http://www.yourdomain.com/whois.php?d=%s

I’d highly recommend you put this script in a password protected directory to prevent abuse!

Leave a Reply

Your email address will not be published. Required fields are marked *