我有我的想法上的驗證碼是如何工作的Codigniter。我無法解釋給你聽清楚,但我希望你能理解下面這個代碼:
添加到您的配置文件
#google reCaptcha
$config['recaptcha_sitekey'] = 'put site key'; //Recaptcha Site key
$config['recaptcha_secretkey'] = 'put secret key'; //Recaptcha Secret Key
將此代碼添加到您的驗證表單
$this->form_validation->set_rules('g-recaptcha-response', 'recaptcha validation', 'required|callback_validate_captcha');
$this->form_validation->set_message('validate_captcha', 'Please check the the captcha form');
和不忘記將此添加到驗證碼所在的控制器中
//ADDITIONAL CODES
function validate_captcha() {
$captcha = $this->input->post('g-recaptcha-response');
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$this->config->item('recaptcha_sitekey')."&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
if ($response . 'success' == false) {
return FALSE;
} else {
return TRUE;
}
}
A DD這個代碼的形式,其中的reCAPTCHA會出現
<div class="g-recaptcha" data-sitekey="<?php echo $this->config->item('recaptcha_sitekey') ?>"></div>
而且不`噸忘記的Javascript
<script src="https://www.google.com/recaptcha/api.js"></script>
如果你想從主頁面中出現兩次驗證碼模態將此代碼添加到您的模式
<script>
createRecaptcha();
function createRecaptcha() {
grecaptcha.render("captcha", {sitekey: "<?php echo $this->config->item('recaptcha_sitekey') ?>", theme: "light"});
}
</script>
添加在您想驗證碼會出現這個代碼
<div id="captcha"></div>
這是我所能做的^ _^
演示:https://www.waraywarayako.ph/
好吧,我有一個建立已,但我不知道如何與表單的其餘產品。有一個名稱字段,電子郵件,電話號碼 - 這些被檢查以查看是否有任何內容,我需要的條件也從recaptcha代碼中獲得價值。我可以複製$ this-> load->庫函數嗎?此外,我沒有任何名爲helper的文件夾或該非易失性文件夾中名爲form的文件 – CQM 2011-04-08 23:19:46
表單助手是[內置助手](http://codeigniter.com/user_guide/helpers/form_helper.html)。我得到的印象你不明白[表單驗證](http://codeigniter.com/user_guide/libraries/form_validation.html)類是如何工作的。你需要設置你的規則,比如'$ this-> form_validation-> set_rules('email','Email','required');'如果它們全部驗證,那麼'$ this-> form_validation-> run()'將返回true。這些文檔通過示例對其工作原理進行了很好的解釋。 – akpb 2011-04-10 01:32:29
好的。所以我下載了代碼。將所有文件移到適當的文件夾中。在config/recaptcha.php文件中設置鍵。然後,我有我的表單提交邏輯,我把$ this-> form_validation-> run()函數。然後在HTML中我做了什麼?我需要顯示用戶輸入的驗證碼。我看到谷歌的代碼將php recaptcha添加到非代碼點火器文檔中,但我不確定哪些部分是相關的。我不知道我應該如何打電話給特定的文件。現在我有 – CQM 2011-04-12 19:52:05