public function user_login()
{
$email = $_POST['email'];
$password = $_POST['password'];
$userdata = $this->em->user_login($email, $password);
$user_info = $this->em->does_user_exist($email, $password);
if ($user_info->num_rows() == 1) {
foreach ($user_info->result() as $row) {
$data = array(
'id' => $row->id,
'username' => $row->username,
'email' => $row->email,
'user_type' => $row->user_type,
'logged_in' => TRUE
);
$this->session->set_userdata($data);
}
if($userdata) {
echo 1;
} else {
echo 'error';
}
}
}
This is my controller where I check if user can login and does user exist if they exist I get the all of the data and set the session. For some reason when I echo the the session username it wont display. What could be wrong?
Here's how I echo the session:
<div>
hello<p><?php echo $this->session->userdata('username'); ?></p>
</div>
<div>
<p><?php echo $data['username']; ?></p>
</div>
Is there any other way to echo a session?