项目作者: srimaln91

项目描述 :
A Codeigniter library to validate Google Recaptcha.
高级语言: PHP
项目地址: git://github.com/srimaln91/codeigniter-recaptcha.git
创建时间: 2017-09-23T13:39:34Z
项目社区:https://github.com/srimaln91/codeigniter-recaptcha

开源协议:MIT License

下载


codeigniter-recaptcha

A Codeigniter library to validate Google Recaptcha.

Getting Started

You need to copy config and library files into yout Codeiginter application.

How to use

  1. Set config variables ( Google recaptcha sitekey and secret. You will be aboe to get those values form https://www.google.com/recaptcha/admin ).

  2. Use the library in your controllers as below

  1. <?php
  2. class Form extends CI_Controller {
  3. /**
  4. * Index Controller
  5. *
  6. * @return void
  7. */
  8. public function index()
  9. {
  10. $this->load->library('form_validation');
  11. $this->form_validation->set_rules('g-recaptcha-response', 'recaptcha', 'trim|required|callback_validateCaptcha');
  12. if ($this->form_validation->run() == FALSE){
  13. //Form Error
  14. }
  15. else{
  16. //Form Success
  17. }
  18. }
  19. /**
  20. * A callback function for validate captcha
  21. *
  22. * @param string $response
  23. * @return boolean
  24. */
  25. public function validateCaptcha($response){
  26. $this->load->library('recaptcha');
  27. if (!$this->recaptcha->Validate($response)){
  28. $this->form_validation->set_message('validateCaptcha', 'The {field} field is incorrect. Please retry.');
  29. return FALSE;
  30. }
  31. return TRUE;
  32. }

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details