Jump to content
Sign in to follow this  
WHMCS Josh

Mass Delete Spam Clients

Recommended Posts

An unfortunate trait of the internet is spam and automated bots disseminating that spam. As a business operator on the internet, you may also receive orders submitted in bulk by automated bots. There can be situations where you need to delete lots of clients with the same first name.

This small script leverages the local API to cleanly delete all clients who match the specified term.

 

 

This script is provided as-is, without warranty, and in the understanding for the potential to permanently and irreversibly delete data. Before running this script, please make a database backup:

<?php
/**
 * Delete spam clients where the firstname contains 5666Q.COM
 * using advanced database interaction and the DeleteClient API
 *
 * @link https://developers.whmcs.com/advanced/db-interaction/
 * @link https://developers.whmcs.com/api-reference/deleteclient/
 *
 * @author     WHMCS Limited <development@whmcs.com>
 * @copyright  Copyright (c) WHMCS Limited 2005-2018
 * @license    https://www.whmcs.com/eula/ WHMCS Eula
 */

require 'init.php';

use WHMCS\Database\Capsule;

// Replace ADMIN_USERNAME with your admin username
$adminUsername = 'ADMIN_USERNAME';

echo '<pre>';

// Loop through all clients where firstname contains 5666Q.COM
foreach (Capsule::table('tblclients')->where('firstname', 'like', '%5666Q.COM%')->get() as $client) {

    // Delete the client with DeleteClient API
    $results = localAPI('DeleteClient', ['clientid' => $client->id], $adminUsername);

    // Check for errors
    if ($results['result'] == 'success') {
        echo "Deleted Client ID: " . $client->id;
    } else {
        echo "Error deleting Client ID: " . $client->id;
    }
}

echo '</pre>';

 

Begin by entering your adminstrator's username on line 19:

$adminUsername = 'ADMIN_USERNAME';

Upload the script to your WHMCS directory, and visit in your browser.

The script will search through all the clients matching the criteria specified in this line:

'firstname', 'like', '%5666Q.COM%'

It will then properly and permanently delete matching clients and associated records.

The last step is to show which clients are deleted, and if a problem was occurred.

 

The file should then be deleted from your server.

 

At the time of writing this post, this script was tested on the latest stable release of WHMCS 7.5.1 and should work with any that fall under Active Support as per the LTS schedule here: https://docs.whmcs.com/Long_Term_Support#WHMCS_Version_.26_LTS_Schedule

If you have any feedback, questions, or concerns that I did not cover in this post, please feel free to reach out!

delete_spam_clients.php

Share this post


Link to post
Share on other sites
On 27/04/2018 at 8:46 AM, WHMCS Josh said:

An unfortunate trait of the internet is spam and automated bots disseminating that spam. As a business operator on the internet, you may also receive orders submitted in bulk by automated bots. There can be situations where you need to delete lots of clients with the same first name.

This small script leverages the local API to cleanly delete all clients who match the specified term.

 

 

This script is provided as-is, without warranty, and in the understanding for the potential to permanently and irreversibly delete data. Before running this script, please make a database backup:


<?php
/**
 * Delete spam clients where the firstname contains 5666Q.COM
 * using advanced database interaction and the DeleteClient API
 *
 * @link https://developers.whmcs.com/advanced/db-interaction/
 * @link https://developers.whmcs.com/api-reference/deleteclient/
 *
 * @author     WHMCS Limited <development@whmcs.com>
 * @copyright  Copyright (c) WHMCS Limited 2005-2018
 * @license    https://www.whmcs.com/eula/ WHMCS Eula
 */

require 'init.php';

use WHMCS\Database\Capsule;

// Replace ADMIN_USERNAME with your admin username
$adminUsername = 'ADMIN_USERNAME';

echo '<pre>';

// Loop through all clients where firstname contains 5666Q.COM
foreach (Capsule::table('tblclients')->where('firstname', 'like', '%5666Q.COM%')->get() as $client) {

    // Delete the client with DeleteClient API
    $results = localAPI('DeleteClient', ['clientid' => $client->id], $adminUsername);

    // Check for errors
    if ($results['result'] == 'success') {
        echo "Deleted Client ID: " . $client->id;
    } else {
        echo "Error deleting Client ID: " . $client->id;
    }
}

echo '</pre>';

 

Begin by entering your adminstrator's username on line 19:


$adminUsername = 'ADMIN_USERNAME';

Upload the script to your WHMCS directory, and visit in your browser.

The script will search through all the clients matching the criteria specified in this line:


'firstname', 'like', '%5666Q.COM%'

It will then properly and permanently delete matching clients and associated records.

The last step is to show which clients are deleted, and if a problem was occurred.

 

The file should then be deleted from your server.

 

At the time of writing this post, this script was tested on the latest stable release of WHMCS 7.5.1 and should work with any that fall under Active Support as per the LTS schedule here: https://docs.whmcs.com/Long_Term_Support#WHMCS_Version_.26_LTS_Schedule

If you have any feedback, questions, or concerns that I did not cover in this post, please feel free to reach out!

delete_spam_clients.php 1.07 kB · 131 downloads

Please advice where to upload the file delete_spam_clients.php

Share this post


Link to post
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.

Guest
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.

Sign in to follow this  

  • Similar Content

    • By mindofmedia
      Hello,
      Like every year where are adjusting our pricing on the local index. 
      But because we still have a few clients that uses our old product gamma we still need to updates these pricing also. While that's fine for the active clients, I can't seems to delete the products that aren't active anymore on any client besides that are cancelled or terminated.
      So that product is still in the clients database (as cancelled or terminated) and most of the times the customer isn't even a customer anymore. Because of that I can't remove the products from Whmcs. I can hide them, retire them that is all fine but they still are in the admin product list (not in dropdown, the actual list where you can see all your products in the admin area).
      So I was wondering, what if I delete all the terminated and cancelled products from the customers client profile.
      But I'm not really sure about that, so I would like to know your opinion. What do you do?
      I think in EU (or BE for that fact), we can't delete the customer profile data, invoices, etc for 10 years (maybe a hard copy of the invoices is fine, don't know). But I don't think that applies on their products (since the actually webhosting is already long gone of course). And if we want we can still see the history on their invoices.
      So what do you do when a customer (or you) cancels (or terminates), what do you do with their profile, history, products, tickets, invoices, etc? Do you delete it, keep it, keep if for a few months, years, decades?
    • By Tycho
      Hello,
      https://gyazo.com/ae7b45883641d2bbd26482f3233e7af2
      I want everything on the left side bar gone. What's the best way to do that without an empty spot? So I want to have the panels in the middle.
      I've looked at google a lot but couldn't get out anyway.
    • By cdeese8
      Might you know of any sneaky ways, or creative things I can do to stop this?
      Can you please tell me how to prevent, block and disable any non-English letters? Specifically, I think it would be great to prevent letters from the Cyrillic script (Russian Alphabet). Literally, every spam ticket I get is from Mother Russia.
      I know there is form captcha, but I don't want to use any services related to google or even the baked in WHMCS. The less steps a visitor has to do to get support the better.
      Thanks for your time,
      https://en.wikipedia.org/wiki/Russian_alphabet https://docs.whmcs.com/Spam_Control don't see anything here don't see anything for search query: site:whmcs.community block russian letters still doing R&D for search operator: bootstrap 3 input field validation block russian letters
    • By HarryAdney
      I see this in Setup > Addon Modules. I use MailChimp; is it safe to delete the legacy module and am I correct in thinking it's the one shown in module/addons/admin?
       
      Cheers
    • By bluesteam
      Hi,
      So I have just signed up with crisp.  My business email address is info@bluesteam.net.  Crisp asks for an email address when signing up and sends you the chat transcripts after the conversation is complete.
      The problem is that Crisp sends these transcripts from some-random-sequence@bluesteam.on.crisp.email
      Now I have piping enabled for info@bluesteam.net for my General Queries Department so I keep getting the transcript opening tickets on the support system.
      NOW I have to go and delete every support ticket that gets opened because blacklisting each email address is pointless because the sequence will always change and never be the same so its useles to blacklist it.
      I want to add a wildcard in the Spam Control System *@bluesteam.on.crisp.email so that NO transcripts can open a ticket but lo and behold, there is no such thing as a wildcard on the Spam Control.
      How can this be?  It's such a simple feature that should be enabled with every spam control system.
      Has anyone got a solution to this?
      Thanks
      Brett
  • 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