Jump to content

Get number of clients


Recommended Posts

this won't specifically tell you how to do it via API, but if you want to use PHP to create a smarty variable, you might take a look at the thread below...




Nice! But the problem is that I need to show it on my website (WordPress) because my main website is not powered by WHMCS. How would I go about that?

Link to comment
Share on other sites

Indirectly you can get this number probably iterating GetClients API function and counting keys but to me it seems a very bad solution. What if you have 2000 clients in your WHMCS? Spamming GetClients for every single visitor on your website and every page view sounds stupid.


The best way for me is very simple. Make a php script on WHMCS, include DB connection, query database to COUNT() tblclients and print the resulting number. Now on Wordpress call this file (a get content should be fine) and job done. You have your number. This solution is better because it's faster and doesn't overload without a valid reasons WHMCS and your webserver. Personally I'll also cache this value.

Link to comment
Share on other sites

Create a file, in the root of your WHMCS, called "clientcount.php". Within that file, put the following code:




// Get the client count
$table = "tblclients";
$fields = "COUNT(*) AS clientcount";
$result = select_query($table,$fields);
while ($data = mysql_fetch_array($result)) {
 $clientcount = $data['clientcount'];

echo $clientcount;



Now you can call this externally, by using the following code:



$clientcount = file_get_contents('http://www.yourdomain.com/clientcount.php'); // Full URL to clientcount.php
echo 'Total Number of Clients: ' . $clientcount;



Hopefully, that helps.

Link to comment
Share on other sites

  • 5 years later...

As this is Googles first answer for whmcs get clients. For wordpress we wrote the following to get ours working, allowing us to tie it into a shortcode as well:

//WHMCS Get Clients Shortcode
//Written by Kyle - www.blacknovadesigns.co.uk
function bnd_whmcs_get_clients_shortcode() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://YOUR-DOMAIN-WHERE-WHMCS-IS/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            'action' => 'GetClients',
            'username' => 'API-TOKEN-ID',
            'password' => 'API-TOKEN-PASSWORD,
            'responsetype' => 'json',
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$results = json_decode($response, true);

echo "<h3>" .$results['totalresults']. "</h3>";
echo "<p>HAPPY CLIENTS</p>";
add_shortcode( 'whmcsgetclients', 'bnd_whmcs_get_clients_shortcode' );

Hopefully this will help for anyone looking to do this them selves in the future.

Edited by BlackNovaDesigns-Kyle
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated