Welcome Guest, Not a member yet? Register   Sign In
how to using session in library...please help me...
#2

[eluser]Dam1an[/eluser]
Firtly, you shoould always use code blocks when you have more then one or two lines of code, I had to paste it in my IDE to be able to easily read your code

Here's some quick code I knocked up

Make sure you autoload session and database

Model:
Code:
<?php
class Login_model extends Model {
    function __construct() {
        // you forgot to call the parent constructor
        parent::Model();
    }
    
    function login($id, $password) {
        $this->db->where('id', $id);
        $this->db->where('password', $password);
        
        return $this->db->get('users');
    }
}
?>

Controller:
Code:
<?php
class Login extends Controller {
    function __construct() {
        parent::Controller();
        $this->load->model('login_model');
    }
    
    function index() {
        $this->load->view('login');
    }
    
    function _process_login() {
        $id = $this->input->post('id');
        $password = $this->input->post('password');
        $query = $this->login->login($id, $password);
        
        if($query->num_rows() == 0) {
            ... failed to login logic here ...
        } else {
            $user = $query->row();
            
            // set the user level in the session
            $this->session->set_userdata('level', $user->level);
            
            ... do the rest of you successful login stuff ...
        }
    }
}
?>

As for only letting you view pages you have the access level to view, just put a check like
Code:
if($this->session->userdata('level') == 1) {
    ... Have correct level to view page ...
} else {
    ... Can't access this page ...
}


Messages In This Thread
how to using session in library...please help me... - by El Forum - 04-20-2009, 12:42 AM
how to using session in library...please help me... - by El Forum - 04-20-2009, 03:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB