Setting and Getting User Data in Session Session Flash Codeigniter


November 12, 2018 2 minutes codeigniter , session , session flash

setting user data

 $session_data = array(
   'type' => "admin",
   'email'     =>     $email,
   'id'   => $res->id,
   'username'   => $res->username,
   'password'   => $res->password,
);
$this->session->set_userdata($session_data);

getting user data

$id = $this->session->userdata( 'id' );

setting flash message in session

$this->session->set_flashdata( 'success', 'All updated successfully' );

getting flash message from session

<?php if ($this->session->flashdata('success')) { ?>
  <div class="alert alert-success"> <?= $this->session->flashdata('success') ?> </div>
<?php } ?>

<?php if ($this->session->flashdata('error')) { ?>
  <div class="alert alert-danger"> <?= $this->session->flashdata('error') ?> </div>
<?php } ?>

See Also