Welcome Guest, Not a member yet? Register   Sign In
Session Problem and captcha problem
#1

[eluser]saad06[/eluser]
Hi,
I want to make a signup form.I am having problem with session and captcha.My flow is like this
signup form->confirm if not confirm then go back else register.
Now i am having problem with validating the captcha that it is not validating the captcha.
Here is my captcha code

View

Code:
<tr>
                <td align="right">
            <span style="color: #ff0000; font-family:Verdana; font-size:x-small">* </span>

            Verification :</td>
                <td>
                <table border="0" cellspacing="1">
                    <tr>
                        <td>&lt;?php echo $cap_img ;?&gt;</td>
                        <td>&nbsp;<b>: </b>
                        &lt;input size="11" value name="code"&gt;
                        &lt;?php echo $cap_msg ;?&gt;
                          </td>
                          &lt;?php if(isset($error)){?&gt;
                            <td style="color:#FF0000">
                            &lt;?php echo $veriferror ?&gt;
                            &lt;?php }?&gt;</td>
                    </tr>
My controller for captcha is
Code:
function index()
            {
             $captcha_result = '';
             $data["cap_img"] = $this -> _make_captcha();
             $data["cap_msg"] = $captcha_result;
            $this->load->library('validation');
$rules['code']="trim|xss_clean|required|callback_check_captcha";
$this->validation->set_rules($rules);
$fields['code']="Captcha code";
$this->validation->set_fields($fields);
            if ($this->validation->run() == FALSE){
                 $data['error']=true;
                 $captcha_result = '';
                 $data["cap_img"] = $this -> _make_captcha();
                 $data["cap_msg"] = $captcha_result;
                 $this->load->view('xxx',$data);
             }
function check_capthca($str)
  {
  $valid=$this->Model->captcha();
  if(!$valid)
  {
  $this->form_validation->set_message('checkcaptcha', 'The %s field is not correct');
  }

    }
My model is
Code:
function captcha()
           {
           //delete old data 2 hours
           $expiration = time()-7200 ;
    $sql = " DELETE FROM captcha WHERE captcha_time < ? ";
    $binds = array($expiration);
    $query = $this->db->query($sql, $binds);

    //checking input
    $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
    $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration);
    $query = $this->db->query($sql, $binds);
    $row = $query->row();

  if ( $row -> count > 0 )
    {
      return true;
    }
   return false;

  }
}
Can anyone help me in validating the captcha and the problem with session is that when the confirmation form is shown, if there is some wrong entry when the user clicks on the back button the values in the fields dissappear. How can i store these values and display it when back is clicked
here is my back button
Code:
&lt;input type="button" value="Back" name="back" onclick="[removed].href='&lt;?=base_url()?&gt;'"&gt;

Thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB