• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session data removed or overwritten

I have set up an update to fail with a database error. I catch the error, log to file, and store an error message for display. Unfortunately, when I redirect to a summary page the messages disappear from my session. The summary page contains a variable to display any messages or '' if none.

Each controller inherits a controller that checks the authentication
if (!$this->ion_auth->logged_in())

Here is where I set the message in the session variables: message and ud_message
                       // This method call deliberately set to fail with db error
try {
    $this->donation->update($transaction_id, $program_id, $friend_id);
} catch (Exception $e) {
     log_message('error', $e->getMessage());
     //On caught error create a flash message
     $this->session->set_flashdata('message', 'Unable to update donation record');
     //Flash message not working try user defined message as well.
     $this->session->set_userdata('ud_message', 'UD Unable to update donation record');
     //Both of the following lines work (when uncommented;-), indicating that the catch block is entered.
     //echo print_r($_SESSION);
     //show_error('Unable to update the donation record.');

Here is the code in the ledger controller where I check the session variable for error messages
       //Checking for the existence of the flash message
       if (NULL !== $_SESSION['message']) {
            $view_content['message'] = $_SESSION['message'];
       else {
           $view_content['message'] = 'no message';
       //Checking for the existence of the flash message
       if (NULL !== $this->session->userdata('ud_message') ) {
            $view_content['ud_message'] = $this->session->userdata('ud_message');
       else {
           $view_content['ud_message'] = 'no message';
       //Prints what is in the session. Identity information is still here but the message and ud_message are not
       echo print_r($_SESSION);
      $this->data['main_content_view'] = $this->load->view('share/ledger_view', $view_content, TRUE);
      $this->load->view('share/default', $this->data);

The identity (Ion Auth) values remain in the session but the other items I added in the error get removed or over-written.

Here is the session printed inside the try catch immediately after setting the flash and userdata variables:
Array ( [__ci_last_regenerate] => 1450750143 [identity] => [email protected] [username] => so and so [email] => [email protected] [user_id] => 2 [old_last_login] => 3333344444 [message] => Unable to update donation record [__ci_vars] => Array ( [message] => new ) [ud_message] => UD Unable to update donation record ) 1

Here is the the session printed out in the ledger controller
Array ( [__ci_last_regenerate] => 1450750445 [identity] => [email protected] [username] => so and so [email] => [email protected] [user_id] => 2 [old_last_login] => 3333344444 ) 1

Any suggestions would be much appreciated

Messages In This Thread
Session data removed or overwritten - by Shawn - 12-21-2015, 07:01 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.