A WHMCS client-area hook that adds a selectable captcha driver — Cap (proof-of-work), Cloudflare Turnstile, or hCaptcha — without using WHMCS's built-in captcha types.
This repository is a SideCloud fork of Hybula's WHMCS Turnstile hook. Shared page detection, admin-area exclusion and the email / password-reset flow stay in one place; only the widget embed, token field and siteverify call change per driver.
By default WHMCS offers two types of captchas, the built-in-easily-cracked GD based captcha and the easily-cracked-privacy-violating reCAPTCHA by Google.
- One active driver, selected in the hook file: Cap, Turnstile or hCaptcha.
- Enable captcha on login, register, checkout, ticket, contact and password-reset pages.
- Password-reset / email forms are detected under all WHMCS friendly URL modes (
pwreset,?rp=,PATH_INFO, rewritten paths). - Account-invite pages render the widget on both login and register forms and still require a valid token on POST.
- Support for themes (auto/dark/light) on Turnstile and hCaptcha.
- Ability to disable credits and have it fully white labeled.
- Ability to exclude captcha when clients are logged in, with an option to keep checkout protected.
- Administrator area is excluded using WHMCS's
ADMINAREAcontext, including admin login before a session exists.
- PHP 8.x (tested on 8.1.27); hook syntax remains PHP 7.2-compatible
- WHMCS 8.x (tested on 8.9.0)
- The PHP cURL extension, for server-side siteverify calls
- Download the latest release and unzip it in the root of your WHMCS installation. The hook file must be placed in
includes/hooks. If you previously installed upstreamhybula_turnstile.php, remove that file so only one captcha hook runs. - Edit
includes/hooks/hybula_cap.phpand sethybulaCaptchaDrivertocap,turnstileorhcaptcha. - Fill the fields for that driver only (see below). Unused driver keys can stay empty.
- Leave
hybulaCapEnabledset totrue. Open a private window to test (an active admin session hides the widget).
Do not copy these constants into configuration.php. Settings live in the hook file. Defining the same names in configuration.php can trigger "Constant already defined" during WHMCS updates.
Shared options (apply to every driver):
hybulaCaptchaDriver:cap(default),turnstileorhcaptchahybulaCapEnabled: master on/off switchhybulaCapExcludeLogin: skip captcha for logged-in clients (except checkout when enabled below)hybulaCapCheckoutLoggedIn: still require captcha on checkout when a client is logged inhybulaCapFailOpen: if siteverify fails to return JSON, allow the request (true) or block it (false)hybulaCapCredits: show a small Hybula / SideCloud credit next to the widgethybulaCapTheme:auto,darkorlight(Turnstile uses the value as-is; hCaptcha mapsautotolight; Cap is styled with CSS)hybulaCapLocations/hybulaCapSelectors: which pages are protected and where the widget is insertedhybulaCapErrorTitle/hybulaCapErrorText/hybulaCapErrorButton: client-visible failure page
- Create a site on your Cap server.
- Set:
hybulaCapUrl: Cap server URL, without a trailing slashhybulaCapSite: site keyhybulaCapSecret: secret key
- Optional:
hybulaCapWidgetScriptif you self-host the widget instead of the default jsDelivr URL.
Token field: cap-token. Verify URL: {hybulaCapUrl}/{hybulaCapSite}/siteverify.
- Create a widget in the Cloudflare dashboard and copy the site key and secret key.
- Set:
hybulaTurnstileSitehybulaTurnstileSecret
Token field: cf-turnstile-response. Verify URL: Cloudflare siteverify (form-encoded, includes remoteip when present).
- Create a site in the hCaptcha dashboard and copy the site key and secret key.
- Set:
hybulaHcaptchaSitehybulaHcaptchaSecret
Token field: h-captcha-response. Verify URL: hCaptcha siteverify (form-encoded, includes remoteip and sitekey).
Existing Cap deployments keep working with almost no change:
- Keep your current
hybulaCapUrl,hybulaCapSiteandhybulaCapSecretvalues. - Add (or leave at default)
const hybulaCaptchaDriver = 'cap';. - New shared options (
hybulaCapCredits,hybulaCapTheme, Turnstile / hCaptcha keys) can stay at their shipped defaults. - Replace
includes/hooks/hybula_cap.phpand re-apply the settings above if you overwrite a customized copy.
To switch later, change hybulaCaptchaDriver and fill that driver's site/secret keys. Cap URL/keys can remain in the file unused.
This hook protects the client area, not administrator authentication. Requests where WHMCS defines
ADMINAREA as true are excluded, including administrator login before an admin session exists and
custom administrator directory names. WHMCS's own administrator authentication and security checks
remain in place. URL paths, query parameters and submitted adminid fields do not grant an exemption.
When upgrading, preserve your existing driver, Cap URL, site keys, secrets and other settings in the hook file. After deployment, check administrator login in a private window and confirm that client login, registration, password reset and checkout still require a valid challenge. These checks require your actual WHMCS installation; the standalone tests below use simulated WHMCS context.
Run php -n tests/run.php for isolated request regressions and php -l includes/hooks/hybula_cap.php
for syntax validation. The tests use synthetic configuration and stub HTTP calls; they do not contact
WHMCS or a captcha provider. Each request runs in a separate PHP process so admin constants cannot leak into
client-area cases. Cases cover Cap, Turnstile and hCaptcha on the critical login, reset, checkout,
admin-exclusion and invite paths. PHP 7.2-compatible syntax is retained.
Contributions are welcome with pull requests (PR).
This project was originally developed by Hybula B.V. and modified by SideCloud.
Apache License, Version 2.0 and the Commons Clause Restriction