• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
login

#1
[eluser]davy_yg[/eluser]

Hello,

I am trying to create login page with CI. Can anyone help me check this codes:

user
----------------
user_name
user_pass


model/admin/login_model.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login model class
*/
class Login_model extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    
    public function validate(){
        // grab user input
        $username = $this->security->xss_clean($this->input->post('user_name'));
        $password = $this->security->xss_clean($this->input->post('user_pass'));
        
        // Prep the query
        $this->db->where('user_name', $username);
        $this->db->where('user_pass', $password);
        
        // Run the query
        $query = $this->db->get('users');
        // Let's check if there are any results
        if($query->num_rows() == 1)
        {
            // If there is a user, then create session data
            $row = $query->row();
            $data = array(
                    'username' => $row->username,
     'password' => $row->password,
                    'validated' => true
                    );
            $this->session->set_userdata($data);
            return true;
        }
        // If the previous process did not validate
        // then return false.
        return false;
    }
}
?>

controller/admin/clogin.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login controller class
*/
class Login extends CI_Controller{
    
    function __construct(){
        parent::__construct();
    }
    
    public function index(){
        // Load our view to be displayed
        // to the user
        $this->load->view('login_view');
    }

  public function process(){
        // Load the model
        $this->load->model('login_model');
        // Validate the user can login
        $result = $this->login_model->validate();
        // Now we verify the result
        if(! $result){
            // If user did not validate, then show them login page again
            $this->index();
        }else{
            // If user did validate,
            // Send them to members area
            redirect('home');
        }        
    }
}
?>

views/admin/login.php

Code:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
&lt;html  xml:lang='en' lang='en'&gt;

&lt;head&gt;    
    &lt;title&gt;Jotorres Login Screen | Welcome &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id='login_form'>
        &lt;form acti echo base_url();?&gt;login/process' method='post' name='process'&gt;
            <h2>User Login</h2>
            <br />            
            <label for='username'>Username</label>
            &lt;input type='text' name='username' id='username' size='25' /&gt;&lt;br />
        
            <label for='password'>Password</label>
            &lt;input type='password' name='password' id='password' size='25' /&gt;&lt;br />                            
        
            &lt;input type='Submit' value='Login' /&gt;            
        &lt;/form&gt;
    </div>
&lt;/body&gt;
&lt;/html&gt;


Also, how to write the routes so that the codes work?

#2
[eluser]Tpojka[/eluser]
Maybe problem is in the form synthax?

Edit: nope, just forum security posts parsing.

#3
[eluser]davy_yg[/eluser]

How to write the routes so that the file works?

note: I have an admin folder in views, controllers & models.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.