
CrawlerDetect
Detect bots from request headers and protect forms from spam without CAPTCHA
- MODX 3
- PHP 8.2


Detects whether the visitor is a bot. Without &userAgent JayBizzle concatenates headers: HTTP_USER_AGENT, HTTP_FROM, HTTP_SEC_CH_UA, and the rest of its list.
Returns: "1" (bot) or "0" (not bot).
Call uncached: [[!isCrawler]] (MODX) or $modx->runSnippet('isCrawler', []) (Fenom). Otherwise the result is shared across visitors.
| Parameter | Description | Default |
|---|---|---|
| userAgent | Explicit string. Empty: JayBizzle headers from the request | — |
| placeholderPrefix | Placeholder prefix for detected bot name | crawlerdetect. |
When a bot is detected, placeholder crawlerdetect.matches (or your prefix) is set to the bot name, e.g. Googlebot. Use it when debugging.
[[!isCrawler:eq=`0`:then=`[[$chatWidget]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('chatWidget')}
{/if}[[!isCrawler:eq=`0`:then=`[[$googleAnalytics]]`]]{if $modx->runSnippet('isCrawler', []) == '0'}
{$modx->getChunk('googleAnalytics')}
{/if}[[!isCrawler:eq=`0`:then=`[[$fullContent]]`:else=`[[$liteContent]]`]]{set $isBot = $modx->runSnippet('isCrawler', [])}
{if $isBot == '0'}
{$modx->getChunk('fullContent')}
{else}
{$modx->getChunk('liteContent')}
{/if}[[!isCrawler]]
[[+crawlerdetect.matches]]{$modx->runSnippet('isCrawler', [])}
{if $modx->getPlaceholder('crawlerdetect.matches')}
Bot: {$modx->getPlaceholder('crawlerdetect.matches')}
{/if}