CodeIgniter Forums
problem on retrieving session userdata - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: problem on retrieving session userdata (/thread-55259.html)



problem on retrieving session userdata - El Forum - 10-17-2012

[eluser]Yogesh_89[/eluser]
hello everyone! I am new in CI.....

i has been created session for login, logout. Now i am saving session data into database. As given in user guide how to save session data, i did all things. Now it saving session data.
Problem is that when i changed config file

$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = true;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

now i am checking for session data is set or not in then it not replied any thing. this is code

I am sending userid and pass from view page to controller
function user_login()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('user_name', 'Username', 'required|alpha_dash');
$this->form_validation->set_rules('password', 'Username', 'required|alpha_dash');
if($this->form_validation->run() == false)
{
$this->index();
}
else
{
$this->load->model('login_model');
if($query = $this->login_model->match_info())
{
$this->load->library('session');
$data = array(
'username' => $this->input->post('user_name'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('user/index');
}
else
{
$this->index();
}
}
}



problem on retrieving session userdata - El Forum - 10-17-2012

[eluser]Yogesh_89[/eluser]
this is code in Model

function match_info()
{
$this->db->where('user_name', $this->input->post('user_name'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('user_login');
if($query->num_rows >=1)
{
return true;
}
}


this is code for welcome page after login

Controller Code

class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('session');
$this->is_logged_in();
}
function is_logged_in()
{
$u_name = $this->session->userdata('is_logged_in');
if(!isset($u_name) || $u_name!=true)
{
echo 'You dont have permission to access this page'.anchor('welcome/index', 'Login now');
die();
}
}
function index()
{
$this->load->view('user_welcome');
}
}
I am entering right id and password but i am getting 'You dont have permission to access this page'.anchor('welcome/index', 'Login this line always.

but if i changed config file $config[‘sess_use_database’] = false;
then it working fine. tell me where i am using wrong coding in my code.

Thanks