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! " ;
}