Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo/print variables in a session array of codeigniter

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!

like image 531
itsover9000 Avatar asked Apr 18 '26 06:04

itsover9000


2 Answers

Use this

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

echo '<pre>';
print_r($session_data);
like image 50
Muhammad Raheel Avatar answered Apr 19 '26 19:04

Muhammad Raheel


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'];
like image 26
diggersworld Avatar answered Apr 19 '26 21:04

diggersworld