reCAPTCHA Codeigniter
v1.0
免費使用庫recaptcha v2進行代碼簽名符4。
此轉換已經移至https://github.com/phpdevsr/recaptcha-codeigniter4
Recaptcha是一項免費服務,可保護您的網站免受垃圾郵件和濫用的侵害。它使用先進的風險分析引擎來分開人類和機器人。借助新的API,您的大量有效的人類用戶無需解決驗證碼即可通過Recaptcha挑戰(有關更多詳細信息,請參見博客)。 recaptcha以小部件的形式出現,您可以輕鬆地添加到博客,論壇,註冊表格等。
查看細節。
要使用recaptcha,您需要為您的網站註冊API鍵對。密鑰對由一個站點密鑰和秘密組成。該站點鍵用於在您的網站上顯示小部件。該秘密授權您的應用程序後端和recaptcha服務器之間的通信以驗證用戶的響應。為了安全目的,需要確保秘密安全。
與作曲家安裝
$ composer require hexageek1337/recaptcha-codeigniter4用GIT克隆安裝手動
$ git clone https://github.com/hexageek1337/reCAPTCHA-Codeigniter
$ cd reCAPTCHA-Codeigniter-main
$ cp app/Config/Settings.php your_application_folder/Config/
$ cp app/Libraries/Recaptcha.php your_application_folder/Libraries/在app/Config/Settings.php文件上設置您的網站密鑰和秘密
public $ recaptcha_site_key = '' ;
public $ recaptcha_secret_key = '' ;
public $ recaptcha_lang = ' id ' ; echo $ this -> recaptcha -> getWidget ();輸出:
< div class =" g-recaptcha " data-sitekey =" xxxxx " data-theme =" light " data-type =" image " data-size =" normal " loading =" lazy " > </ div >通過PASS數組參數更改默認主題
echo $ this -> recaptcha -> getWidget ( array ( ' data-theme ' => ' dark ' ));通過PASS數組參數更改默認類型
echo $ this -> recaptcha -> getWidget ( array ( ' data-theme ' => ' dark ' , ' data-type ' => ' audio ' )); echo $ this -> recaptcha -> getScriptTag ();輸出:
< script type =" text/javascript " src =" https://www.google.com/recaptcha/api.js?render=onload&hl=id " defer > </ script >通過通過陣列參數更改渲染值
echo $ this -> recaptcha -> getScriptTag ( array ( ' render ' => ' explicit ' ));通過通過數組參數更改默認語言
echo $ this -> recaptcha -> getScriptTag ( array ( ' render ' => ' explicit ' , ' hl ' => ' zh-TW ' ));調用recaptcha siteverify api,以驗證用戶是否通過g-recaptcha-response post參數。
$ captcha = $ this -> request -> getPost ( ' g-recaptcha-response ' );
$ response = $ this -> recaptcha -> verifyResponse ( $ captcha );檢查成功或失敗
if ( isset ( $ response [ ' success ' ]) and $ response [ ' success ' ] === true ) {
echo " You got it! " ;
}