Echo/print variables in a session array of codeigniter

36,217

Solution 1

If you set data like this:

$this->session->set_userdata('newdata', $newdata);

You will need to access it like this:

$this->session->userdata('newdata');

So you could do:

// dump all content
var_dump($this->session->userdata('newdata'));

// or access array indexes like so.
$post_array = $this->session->userdata('newdata');
echo $post_array['index'];

Solution 2

Use this

$session_data = $this->session->all_userdata();

echo '<pre>';
print_r($session_data);

Solution 3

It will be an array so you cant display the contents using echo. use print_r() for displaying the array.

Share:
36,217

Related videos on Youtube

itsover9000
Author by

itsover9000

Updated on July 11, 2020

Comments

  • itsover9000
    itsover9000 almost 4 years

    I'm trying to write a code where I use this particular line of code to store my post values in a session array

    $this->session->set_userdata('newdata', $newdata);
    

    The problem is, I can not seem to echo out the values inside it.

    This is how I echo them out:

    <?php echo $this->session->userdata('suffix'); ?>
    

    Is there another way to echo out sessions?

    Thanks in advance!

  • Peon
    Peon over 11 years
    He is trying to echo not the whole session, but only a specific element, which, most likely, will be a string, but who knows.
  • Admin
    Admin over 6 years
    how to display it in view page that session value