CodeIgniter reCaptcha麻烦

好的,我在本网站上看到过类似的问题,但他们没有所有的手持细节我 正在寻找这个特定问题!</ p>

我在使用JS版本的reCaptcha和为CodeIgniter 1.7.1制作的PHP版本之间处于不确定状态</ p>

< p>使用JS版本我将它显示在生成的HTML中,但我不确定如何将正确的结果传递给PHP表单。 周围的表单目前只在PHP中发布是否有“任何”文本输入,而不是它是否是正确的文本。 我可以监视验证码文本输入字段以查看是否有任何提交,但这不会检查实际的javascript以获得正确的结果。 我需要一个PHP函数调用,它可以从javascript通过Recaptcha.create生成的HTML调用。</ p>

你可能会想:既然codeigniter是PHP,为什么不只是使用PHP版本 recaptcha? CodeIgniter结构是我处理过的最不直观的PHP和MVC结构。 在我正在编辑的这个网站上找到必要的函数调用已经变成了一个逆向工程练习。</ p>

我还有一个PHP版本,在这里制作 https://github.com/seanmcgary/Codeigniter-ReCaptcha ,就像经典的CodeIgniter风格一样,文档基本上不存在。 我知道该版本适用于CodeIgniter 1.7,但我不知道它是什么版本的reCaptcha。 </ p>

请不要将我链接到codeigniter wiki,只是相关帮助。 </ p>

实现JS版本和PHP版本的部分工作变得令人费解,因为一个版本可能</ em>更实用。 所以我问你们,谢谢!</ p>
</ div>

展开原文

原文

Okay all, I have seen similar questions asked on this site, but they don't have all the handholding details I'm looking for on this particular issue!

I am in limbo between using the JS version of reCaptcha and a PHP version made for CodeIgniter 1.7.1

With the JS version I have it displayed within the generated HTML but I'm not sure how to get the proper result passed through to the PHP form. The surrounding form currently only posts in the PHP whether there was "any" text input, not if it was proper text. I can monitor the captcha text input field to see if anything was submitted, but this doesn't check the actual javascript for a proper result. I need a PHP function call that can get a call from the HTML that the javascript generates with Recaptcha.create.

You might be thinking: Since codeigniter is PHP why not just use the PHP version of recaptcha? Well the CodeIgniter structure is the most unintuitive PHP and MVC structure I've dealt with. Finding the necessary function calls on this site I am editing has turned into a reverse engineering exercise.

I also have a PHP version, made here https://github.com/seanmcgary/Codeigniter-ReCaptcha, and just like in classic CodeIgniter flavor, the documentation is basically nonexistent. I know that version is for CodeIgniter 1.7, but I don't know what version of reCaptcha it is.

Please don't link me to the codeigniter wiki, just relevant assistance.

It is becoming convoluted to work on implementing the JS version, and parts of a PHP version because one version might be more practical. So I'm asking you guys, thanks!

2个回答

This wiki article and library are extremely simple. Because you don't want just a link here is some sample code from the wiki article to get you started.

The code is really quite self explanatory. Set up your config with your public and private keys, then in your controller load the recaptcha & form_validation libraries and show the proper view depending on the status of the validation.

config/recaptcha:

$config['recaptcha'] = array(
  'public'=>'YOUR PUBLIC KEY',
  'private'=>'YOUR PRIVATE KEY',
  'RECAPTCHA_API_SERVER' =>'http://www.google.com/recaptcha/api',
  'RECAPTCHA_API_SECURE_SERVER'=>'https://www.google.com/recaptcha/api',
  'RECAPTCHA_VERIFY_SERVER' =>'www.google.com',
  'RECAPTCHA_SIGNUP_URL' => 'https://www.google.com/recaptcha/admin/create',
  'theme' => 'white'
);

controller:

function index()
  {
    $this->load->library('recaptcha');
    $this->load->library('form_validation');
    $this->lang->load('recaptcha');
    $this->load->helper('form');

    if ($this->form_validation->run()) 
    {
      $this->load->view('recaptcha_demo',array('recaptcha'=>'Yay! You got it right!'));
    }
    else
    {
      //the desired language code string can be passed to the get_html() method
      //"en" is the default if you don't pass the parameter
      //valid codes can be found here:http://code.google.com/apis/recaptcha/docs/customization.html#i18n
      $this->load->view('recaptcha_demo',array('recaptcha'=>$this->recaptcha->get_html()));
    }
  } 
dongqixian8474
dongqixian8474 <? $这 - >负载>视图( 'recaptcha.php'); $ publickey =“thekeynumbersandgibberish”; echo get_html($ publickey); 这>目前打破我的HTML页面,我想我没有使用代码点火器语法调用文件并正常运行。 什么是正确的语法? 这不包含在代码点火器文档中。
9 年多之前 回复
duanhe6718
duanhe6718 好的。 所以我下载了代码。 将所有文件移动到相应的文件夹。 在config / recaptcha.php文件中设置密钥。 然后我在表单提交逻辑中放入了$ this-> form_validation-> run()函数。 那么在HTML中我做了什么? 我需要显示用户输入的验证码。 我看到google的代码将php recaptcha添加到非代码点火器文档中,但我不确定哪些部分是相关的。 而且我不确定我应该如何调用特定文件。 现在我有
9 年多之前 回复
dongzan0108
dongzan0108 表单助手是一个内置的助手。 我得到的印象是你不理解表单验证类的工作原理。 您需要设置规则,例如$ this-> form_validation-> set_rules('email','Email','required'); 如果它们都验证,那么$ this-> form_validation-> run()将返回true。 通过示例,文档对其工作原理进行了很好的解释。
9 年多之前 回复
douzi1350
douzi1350 好的,我已经设置好了,但我不确定它是如何与表单的其余部分一起工作的。 有一个名称字段,电子邮件,电话号码 - 检查这些是否有任何内容,我需要条件也从recaptcha代码中获取值。 我可以只复制$ this-> load->库函数吗? 此外,我在这个名为helper的文件夹中没有任何内容,或者在该不存在的文件夹中没有任何名为form的文件
9 年多之前 回复

I have my on idea how recaptcha works on Codigniter. I cannot explain it to you clearly but I hope you can understand this codes below:

Add this to your config files

#google reCaptcha
$config['recaptcha_sitekey'] = 'put site key'; //Recaptcha Site key
$config['recaptcha_secretkey'] = 'put secret key'; //Recaptcha Secret Key

Add this code to your validation form

$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');

and dont forget to add this to the controller where the recaptcha will validate

//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;
        }
    }

Add this codes to the form where recaptcha will appear

 <div class="g-recaptcha" data-sitekey="<?php echo $this->config->item('recaptcha_sitekey') ?>"></div> 

And don`t forget the Javascript

<script src="https://www.google.com/recaptcha/api.js"></script>

And if you want to appear recaptcha twice from main page to modal add this code to your modal

<script>
    createRecaptcha();
    function createRecaptcha() {
    grecaptcha.render("captcha", {sitekey: "<?php echo $this->config->item('recaptcha_sitekey') ?>", theme: "light"});
    }
</script>

add this code for where you want recaptcha will appear

<div id="captcha"></div>

This is all I can do ^_^

Demo: https://www.waraywarayako.ph/

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐