Welcome Guest, Not a member yet? Register   Sign In
Captcha helper problem
#10

[eluser]SaSa[/eluser]
ok.my codes:

CI_Controller:
Code:
function index()
    {
    if($this->session->userdata('login') || $this->session->userdata('logged'))
        {
            redirect('admin/adminindex');
        }else {
    //************** check validation **************//
    $useradmin = $this->input->post('useradmin');
    $passadmin = $this->input->post('passadmin');
    $captcha = $this->input->post('captcha');    
        //If succses fulll fild        
            if($this->login_model->validation_login($useradmin, $passadmin, $captcha))
            {
                $data = array('login' => $useradmin, 'logged'=>true);
                $this->session->set_userdata($data);
                redirect('admin/adminindex');
            }
            else
        {
        $this->session->cookie_monster($this->input->post('remember_me') ? FALSE : TRUE);
        //************** create captcha **************//
        $vals = array(
            'img_path'     => './captcha/',
            'img_url'     => 'captcha/',
        );
        $cap = create_captcha($vals);
        $data['cap'] = $cap;
        $this->login_model->create_captcha($cap);
        
                $this->load->view('admin/login', $data);
            }
        }
    }


CI_Model:
Code:
function validation_login($useradmin, $passadmin, $captcha)
    {
    // validation useradmin //
        $query = $this->db->get_where('login', array('useradmin' => $useradmin));
    if ($query->num_rows()==1) {
        return true;
        $user_query  = '1';
    } else {
        return false;
        $user_query = '0';        
    }
    
    // validation passadmin //
    $query = $this->db->get_where('login', array('passadmin' => sha1($passadmin)));
    if ($query->num_rows()==1) {
        return true;
        $pass_query = '1';
    } else {
        return false;
        $pass_query = '0';
    }
    
    // validation captcha //
    // First, delete old captchas
    $expiration = time()-900; // Two hour limit
    $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);    
    
    // Then see if a captcha exists:
    $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
    $binds = array($captcha, $this->input->ip_address(), $expiration);
    $query = $this->db->query($sql, $binds);
    $row = $query->row();
    if ($row->count == 0)
    {
        echo 'not ok';
        $captcha_query = "0";
        return FALSE;
    }else {
        echo 'not ok';
        $captcha_query = "1";
        return TRUE;
        
    }
    
    return json_encode($user_query.$pass_query.$captcha_query);
    }

view:
Code:
&lt;form action="&lt;?php echo base_url();?&gt;login" method="post" accept-charset="utf-8" &gt;
                            &lt;input type="text" name="useradmin" value="" id="input_username" placeholder="username" /&gt;
                            <div class="result_username"></div>
                            <br/>
                            &lt;input type="password" name="passadmin" value="" id="input_password" placeholder="password" /&gt;
                            <div class="result_password"></div>
                            <br/>                            
                            <div id="capcher_code">&lt;?= $cap['image'];?&gt;</div>
                            &lt;input type="text" name="captcha" value="" id="input_code" /&gt;
                            <div class="result_capcher"></div>
                            &lt;input type="submit" value="" id="login_submit" /&gt;                        
&lt;/form&gt;


Messages In This Thread
Captcha helper problem - by El Forum - 07-05-2011, 01:39 AM
Captcha helper problem - by El Forum - 07-05-2011, 07:05 AM
Captcha helper problem - by El Forum - 07-05-2011, 10:26 AM
Captcha helper problem - by El Forum - 07-05-2011, 11:23 AM
Captcha helper problem - by El Forum - 07-05-2011, 11:52 AM
Captcha helper problem - by El Forum - 07-05-2011, 12:21 PM
Captcha helper problem - by El Forum - 07-05-2011, 12:30 PM
Captcha helper problem - by El Forum - 07-05-2011, 08:33 PM
Captcha helper problem - by El Forum - 07-05-2011, 08:49 PM
Captcha helper problem - by El Forum - 07-06-2011, 12:39 AM
Captcha helper problem - by El Forum - 07-06-2011, 09:30 AM
Captcha helper problem - by El Forum - 07-06-2011, 09:57 AM
Captcha helper problem - by El Forum - 07-06-2011, 11:26 AM
Captcha helper problem - by El Forum - 07-06-2011, 01:52 PM
Captcha helper problem - by El Forum - 07-06-2011, 11:59 PM
Captcha helper problem - by El Forum - 07-07-2011, 12:31 AM
Captcha helper problem - by El Forum - 07-07-2011, 01:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB