CodeIgniter Forums
[SOLVED]session question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED]session question (/showthread.php?tid=48091)



[SOLVED]session question - El Forum - 01-04-2012

[eluser]the_unforgiven[/eluser]
i have set this in my controller:
Code:
if($query) // if the user's credentials validated...
{
    
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true,
'group_id' => 2  // But this line isn't right has the group_id is an INT(11)
);
$this->session->set_userdata($data);
redirect('/');
}
So what should the line look like as its not setting the session correctly in sessions table in user_data:
Code:
a:4:{s:9:"user_data";s:0:"";s:8:"username";s:8:"testuser";s:12:"is_logged_in";b:1;s:8:"group_id";i:2;}
And if i go into phpmyadmin i can change
Code:
group_id”;i:2;
to
Code:
group_id”;s:2;
which then works but need to know what the line commented above needs to be in order to do this on set_userdata.



SOLVED BY DOING THIS:
Code:
function home()
{
  if ($this->session->userdata('group_id') == '1') { // THIS LINE WORKS
  $data['ptitle'] = "Dashboard";
  $data['heading'] = "Welcome";
  $this->load->view('admin/home', $data);
  }else { redirect('admin/restricted'); }
}