Magento 2
CaptchaLa 官方 Magento Open Source 與 Adobe Commerce 2.4 模組。不需撰寫程式碼,即可為六個前台表單加入驗證碼檢查,每個表單都有各自的開關。
每個元件皆以伺服端簽發、單次使用的權杖為後盾,每次送出都會在 Magento 執行表單的 controller 之前先於您的伺服器上驗證。
涵蓋範圍
| 表單 | Action | 設定 |
|---|---|---|
| 顧客登入 | login | Protect customer login |
| 顧客註冊 | register | Protect customer registration |
| 忘記密碼 | lost_password | Protect forgot-password |
| 聯絡我們 | contact_form | Protect contact form |
| 商品評論 | comment | Protect product reviews |
| 寄給朋友 | generic_form | Protect "send to friend" |
六項預設皆為開啟。驗證失敗時,請求會被中止,Magento 會顯示錯誤訊息,並將訪客導回表單。
目前尚不涵蓋:結帳流程,以及結帳中使用的登入彈出視窗。
系統需求
- Magento Open Source 或 Adobe Commerce 2.4.x
- PHP 8.1 至 8.4
- 一個 CaptchaLa 帳號 —— 於
dash.captcha.la取得您的 App Key + App Secret
安裝
將 GitHub 儲存庫中的
CaptchaLa/資料夾複製到app/code/,模組會位於app/code/CaptchaLa/Captcha/。在 Magento 根目錄安裝 PHP SDK 並啟用模組:
bashcomposer require captchala/captchala-php bin/magento module:enable CaptchaLa_Captcha bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
設定
在後台開啟 Stores → Configuration → Customers → CaptchaLa:
- 將 Enable 設為 Yes。
- 貼上您的 App Key 與 App Secret。
- 選擇 Widget mode 與 Language,並為要保護的表單設定 Protect … 開關。
- 按 Save Config,接著清除快取。
在 Enable 設為 Yes 且兩組金鑰都儲存之前,模組不會啟用。各個 website 或 store view 可以使用不同的設定。
| 設定項目 | 預設值 | 說明 |
|---|---|---|
| Enable | 否 | 總開關。關閉時,CaptchaLa 既不顯示也不驗證。 |
| App Key | — | 來自 CaptchaLa 控制台的公開金鑰。必填。 |
| App Secret | — | 伺服端密鑰,用於簽發與驗證權杖。必填;加密儲存,絕不傳送到瀏覽器。 |
| Widget mode | bind | bind(訪客按下表單送出按鈕時進行驗證)、popup、float 或 embed(表單內的驗證列)。 |
| Language | auto | BCP-47 標籤,例如 ja 或 pt-BR;或 auto 跟隨訪客的瀏覽器。 |
| Protect …(六個開關) | 是 | 與上表中的表單一一對應。 |
| Skip CAPTCHA for logged-in customers | 是 | 已登入的顧客不會被要求驗證。 |
螢幕截圖



注意事項
- 全頁快取。 受保護的頁面可以繼續保留在 Magento 的全頁快取中:頁面載入時,元件會從您的商店取得新的權杖。
- 內容安全政策(CSP)。 模組會將 CaptchaLa 的主機加入 Magento 的 CSP 白名單,其內嵌指令碼也帶有 Magento 的 CSP nonce,因此不需要修改 CSP。
疑難排解
- 沒有顯示元件。 確認目前檢視的範圍中 Enable 為 Yes、兩組金鑰都已儲存,且該表單的 Protect … 開關已開啟。接著清除快取。
- 每次送出都被拒絕。 確認 App Key 與 App Secret 屬於同一個應用程式,並已在控制台中為該應用程式允許您商店的網域。
- 試用。 使用公開的測試金鑰,無需帳號即可檢查完整流程。