Reputation: 922
I'm using codeigniter session library to hold data that is used in a series of 3 pages and I'm experiencing strange behavior. My session variables remain in tact but the values disapear. Even stranger: I'm trying to store a serialized array in my session data and the first item of the array ends up being stored in a different variable?
I've attached a link that starts at the first page in the series where it is possible to click to the next page. I've printed the user_session data at the top of both pages (the third page isn't set up yet).
http://playmatics.com/nypl/site/index.php/member_area/quest/accept_quest/12
Sessions work everywhere else, for example I'm using a session to store login data and that works fine.
I've attached my controller and view below
//CONTROLLER:
function accept_quest() {
$assoc_quest_id = end($this->uri->segments);
if(!isset($quest_id)) {
redirect('member_area/quest');
//SEND A MESSAGE: NO QUEST STARTED
}
$quest_rows = $this->quest_model->get_quest_with_images($assoc_quest_id);
$quest = current($quest_rows);
$images = $this->pull_out_images($quest_rows);
//the data array is used both in the session,
//to pass values over to the next function in the quest chain
//and in the template
$data = array();
$data['quest_id'] = $assoc_quest_id;
$data['instruction_text'] = $quest->instructions;
$data['quest_title'] = $quest->name;
$data['quest_time_limit'] = $quest->time_limit;
$data['points_awarded'] = $quest->points_availible;
$data['quest_images'] = serialize($images);
//save data in a flash session to be used in the next function call in the quest chain: quest_action
$this->session->set_userdata($data);
print_r($this->session->all_userdata());
//the following data aren't needed in the session so they are added to the data array after the session has been set
$data['annotation_text'] = $quest->note;
$data['main_content'] = 'quests/quest_desc';
$this->load->view('includes/template', $data);
}
function quest_action() {
print_r($this->session->all_userdata());
$quest_id = $this->session->userdata('quest_id');
echo "the quest id is: $quest_id";
if(!isset($quest_id)) {
redirect('member_area/quest');
//SEND A MESSAGE: NO QUEST STARTED
}
$data['quest_id'] = $quest_id;
$data['quest_title'] = $this->session->userdata('quest_title');
$data['quest_images'] = $this->session->userdata('images');
$data['instruction_text'] = $this->session->userdata('instructions');
$data['quest_time_limit'] = $this->session->userdata('quest_time_limit');
$data['main_content'] = 'quests/quest_action';
$this->load->view('includes/template', $data);
}
//VIEW
//quest_desc:
<h1><?= $quest_title ?></h1>
<div id="quest_elements">
<figure>
<? foreach(unserialize($quest_images) as $image): ?>
<img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/>
<? endforeach; ?>
<figcaption>annotation: <?= $annotation_text ?></figcaption>
</figure>
<?= anchor("member_area/quest/quest_action", "Start Quest", array('title' => 'start quest')); ?>
</div><!-- end quest_elements -->
//quest_action:
<h1><?= $quest_title ?></h1>
<div id="quest_elements">
<figure>
<? foreach(unserialize($quest_images) as $image): ?>
<img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/>
<? endforeach; ?>
<figcaption>instructions: <?= $instruction_text ?></figcaption>
</figure>
<div id="timer">
<?= $quest_time_limit; ?>
</div>
<?= anchor("#start_timer", "Start Timer", array('title' => 'start quest timer')); ?>
</div>
Upvotes: 1
Views: 1693
Reputation: 62392
If you are hitting the cookie size limit, I would suggest switching to CodeIgniter's native Database Sessions class. This enables you to store session information in a database, effectively removing the cookie size limitation, you are simply restricted to the size of the user_data
field in the ci_sessions
database.
Following the link above, the section on utilizing database sessions is near the bottom, providing you the proper DB schema and the config switch to database sessions.
Upvotes: 3
Reputation: 8382
As others have said, it is likely that you are hitting the 4k cookie limit of CI's session library. There are other alternative libraries available that use standard PHP sessions - http://codeigniter.com/wiki/PHPSession/ and http://codeigniter.com/wiki/Native_session/ for instance.
Upvotes: 2