WHMCS Hacks – Get Domain TLD List

WHMCS provides various APIs for developer, but recently I  need an API to get list of the TLD domain for external search, mean like I don’t want to update the integration code everytime I add a new TLD. I searched through out the entire APIs but none of it provides this features so I  write it myself to access directly to database.


You can download the entire script:

[box type=”info”]
Click here for Preview.

First of all I create API folder inside WHMCS folder, and then I created new file called “getdomainlist.php”.


//Remove this if you want authentication for using the querry
//How to use?
//$mysecretkey = "CHANGE_THIS_TO_YOUR_SECRET_KEY";
//to your configuration.php

$key = filter_input(INPUT_GET, 'mysecretkey', FILTER_SANITIZE_SPECIAL_CHARS);
$key = filter_input(INPUT_POST, 'mysecretkey', FILTER_SANITIZE_SPECIAL_CHARS);

die("Error:Invalid secret key");


$link = mysql_connect($db_host, $db_username, $db_password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
$result = mysql_query("SELECT `extension` FROM `tbldomainpricing` ORDER BY `order`");
//$num_rows = mysql_num_rows($result);
while ($data = mysql_fetch_row($result)) {

    foreach ($data as $tld)
        $domaintld[] = $tld;


echo json_encode($domaintld);


Now you can call this file anywhere for example if you want to place a domain search on your WordPress site. The output of the previous file is in JSON format so you also can fetch it by using Javascript.

<!DOCTYPE html>

    <title>Domain checker</title>


<form id="searchbox" target="_top" action="https://www.mahadirnetwork.com/billing/cart.php?a=add&domain=register" method="post">
   <input type="hidden" name="token" value="d2f67121e1972114638418926f79bc46e69bd818" />
   <input id="search" name="sld" type="text" placeholder="Your preferred domain name, example: kedaibizahmad">
   <select id="tld"  name="tld">
   $domain = json_decode(file_get_contents("http://mahadirnetwork.com/billing/api/getdomainlist.php"),1);
   foreach($domain as $tld){
     echo '<option value="'.$tld.'">'.$tld.'</option>';
    <input id="submit" type="submit" value="Search">


Tags : ,

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

In an effort to prevent automatic filling, you should perform a task displayed below.