[eluser]Unknown[/eluser]
Hello , i am new in CI and trying to make a member only area , everything is ok , but i have a problem making the member area check if the user logged in or not!!
when user logging he should redirect to
http://localhost/index.php/admin/members
and its done , but always i got message : You don't have permission to access this page.!! please Login!!! even the provided username and password is correct.
My CI version : 2.1
members Controller
Code:
class members extends CI_Controller{
function __construct() {
parent::__construct();
$this->is_logged_in();
}
function index(){
$this->load->view('admin/members');
}
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true)
{
echo 'You don\'t have permission to access this page.!! please <a href="../admin/login">Login</a>';
die();
}
}
}
Login Controller
Code:
class login extends CI_Controller {
function index()
{
$data['main_content'] = 'admin/login_form';
$this->load->view('admin/includes/template', $data);
}
function validate_credentials()
{
$this->load->model('admin/user_login_model');
$query = $this->user_login_model->validate();
if($query)//if the login detalis right then
{
$data = array(
'username' =>$this->input->post('username'),
'is_loggedin' => true
);
$this->session->set_userdata($data);
redirect('admin/members');
}
else {
$this->index();
}
}
function forgot(){
$data['main_content'] = 'admin/forgot_form';
$this->load->view('admin/includes/template', $data);
}
}
?>
so how i can fix that ?
Thanks