html - 我的谷歌验证码无法正常工作

标签 html css codeigniter-2

我想在我的注册页面中使用验证码安全性,但是当我用错误的验证码填写表单并提交表单时。问题是在我的注册页面中查看两个页面。并用正确的验证码再次填写此表格,但他们再次遇到同样的问题并显示不正确的验证码。

控制者

public function user_signup($data = NULL){
                $this->load->library('form_validation');
                $this->recaptcha->recaptcha_check_answer($_SERVER['REMOTE_ADDR'],$this->input->post('recaptcha_challenge_field'),$this->input->post('recaptcha_response_field'));

                $this->form_validation->set_rules('Username', 'Username', 'required|trim|is_unique[users.Username]');
                $this->form_validation->set_rules('First_name', 'First Name', 'required|trim');
                $this->form_validation->set_rules('Last_name', 'Last Name', 'required|trim');
                $this->form_validation->set_rules('Email', 'Email', 'required|trim|valid_email');
                $this->form_validation->set_rules('Password', 'Password', 'required|trim|md5');
                $this->form_validation->set_rules('Conf_password', 'Confirm Password', 'required|trim|matches[Password]');
                $this->form_validation->set_message('is_unique', 'Username already exists.');
                if($this->form_validation->run() && $this->recaptcha->getIsValid()){
                    //Call to recaptcha to get the data validation set within the class. 

                    $form_data = array();
                        $form_data['Username'] = $this->input->post('Username');
                        $form_data['First_name'] = $this->input->post('First_name');
                        $form_data['Last_name'] = $this->input->post('Last_name');
                        $form_data['Email'] = $this->input->post('Email');
                        $form_data['Password'] = $this->input->post('Password');
                        $form_data['Conf_password'] = $this->input->post('Conf_password');

                        $this->load->model('User');
                        $this->User->sign_up($form_data);
                        $data['msg']= "Account Created Sucessfuly";

                       }else{
                        if(!$this->recaptcha->getIsValid()){
                        $this->session->set_flashdata('error','incorrect captcha');                     
                        }
                    }

                redirect("Users/signup", $data);
        }

型号

public function sign_up($form_data){
       $this->db->insert('users', $form_data);
}

查看

                            <?php
                            //$val = NULL;
                            if(isset($results->id)){
                                $val = "Update";
                                $action = "Users/user_update/".$results->id;
                            }else{
                                $val= "Register";
                                $action = "Users/user_signup";
                            }; ?>

                            <?php echo form_open($action); ?>
                            <?php echo form_input(array('name'=>'Username', 'class'=>'input-xlarge', 'type'=>'text', 'placeholder'=>'Username', 'required' => 'required', 'value'=>$u)); ?>
                            <?php echo form_error('Username', '<div class="alert alert-error">', '</div>'); ?>
                            <?php echo form_input(array('name'=>'First_name', 'class'=>'input-xlarge', 'type'=>'text', 'placeholder'=>'First Name', 'required' => 'required', 'value'=>$f)); ?>
                            <?php echo form_error('First_name', '<div class="alert alert-error">', '</div>'); ?>
                            <?php echo form_input(array('name'=>'Last_name', 'class'=>'input-xlarge', 'type'=>'text', 'placeholder'=>'Last Name', 'required' => 'required', 'value'=>$l)); ?>
                            <?php echo form_error('Last_name', '<div class="alert alert-error">', '</div>'); ?>
                            <?php echo form_input(array('name'=>'Email', 'class'=>'input-xlarge', 'type'=>'text', 'placeholder'=>'Email', 'required' => 'required', 'value'=>$e)); ?>
                            <?php echo form_error('Email', '<div class="alert alert-error">', '</div>'); ?>
                            <?php echo form_input(array('name'=>'Password', 'class'=>'input-xlarge', 'type'=>'password', 'placeholder'=>'Password')); ?>
                            <?php echo form_error('Password', '<div class="alert alert-error">', '</div>'); ?>
                            <?php echo form_input(array('name'=>'Conf_password', 'class'=>'input-xlarge', 'type'=>'password', 'placeholder'=>'Confirm Password')); ?>                           
                            <?php echo form_error('Conf_password', '<div class="alert alert-error">', '</div>'); ?>

                            <?php if(!isset($results->id)){echo $recaptcha_html;} ?>
                            <?php if ($this->session->flashdata('error') !== FALSE) { echo '<div class="alert alert-error">'.$this->session->flashdata('error').'</div>'; } ?>
                         <div class="login-actions">                           
                             <span><input type="checkbox"> <span class="remember">I have read & agree</span></span>                 
                             <span><?php echo form_submit(array('value'=>$val, 'class'=>'btn btn-large btn-warning pull-right', 'type'=>'submit')); ?></span>
                        </div>
                    <?php echo form_close(); ?>

最佳答案

将此代码放在 if(!$this->recaptcha->getIsValid()){ 之后并回显消息...

    if($this->input->post('recaptcha_response_field') =="" ){
         $this->session->set_flashdata('error','fill up this code');
    }else{
         $this->session->set_flashdata('error','incorrect captcha');
    }

如果您显示消息“帐户创建成功”。使用设置即显信息 正确阅读此链接

http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

How to display error messages in CodeIgniter

关于html - 我的谷歌验证码无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17316614/

相关文章:

html - 图像放大使用 UL 和 LI 不工作

javascript - css 响应式网格 - 行之间的水平线

html - 如何通过CSS添加背景图片或主题?

javascript - 从 ajax 请求 (jQuery) 到 Code Igniter Controller 的 500 错误

php - 我正在尝试扩展 CodeIgniter 表单验证库

javascript - jQuery 过滤元素并在类不存在且它是第一个元素时添加类

html - 在不按下其父 div 的情况下向导航链接添加底部边框

CSS:删除选择元素中默认选项的灰色突出显示

mysql - 单列的代码点火器总和查询

html - Angular(4 或 2)如果满足条件则应用 CSS