Question

I have an odd situation. consider the following scenario:

  1. form on page posts to another domain
  2. that domain processes data, and posts back to controller A
  3. controller A processes returned data, and sets flash session vars
  4. controller A redirects to controller B
  5. session values set in controller A are lost.

Now, I have noticed that if I eliminate step 4; the session values are not lost. It is only happening after calling Response::redirect().

Following is the relevant code in controller A's post handler (in this case, $vars is set to Input::post(); and the renew() method does a soap call to another API, and returns response data.):

$success_object = $this->renew( $vars );
$persist_through_redirect = array(
    'accountId' => $success_object->account->accountId,
    'expireDate' => $success_object->account->expireDate,
    'createDate' => $success_object->account->createDate,
    'due_amount' => $success_object->account->lastPaymentAmt,
    'offer_name' => $offer_name,
    'member_name' => $vars['first_name'] . ' ' . $vars['last_name']
);
return $this->redirect('success/', $persist_through_redirect);

And this is the code behind method redirect():

private function redirect($redirect_endpoint, $redirect_values = null) { 
    Session::set_flash('flash_redirect', $redirect_values);
    Response::redirect($redirect_endpoint);
}

Finally, here is the code in controller B that accesses the session data:

$information = Session::get_flash('flash_redirect');
if(isset($information)) {
    View::set_global('membership',  $information);
}
// set the locale based on fuel's setting
View::set_global('locale', str_replace( '_', '-', Fuel::$locale ));
return View::forge('successes/success_card');

It gets weirder though. Not all session data is lost. Any session data I had set in the before() method is staying put.

I'm very stumped on this one. Any ideas why my session data is lost?

Was it helpful?

Solution

As it turned out, the core issue was that my session cookie was exceeding 4kb.

What was happening is that when I made a call to Response::redirect(), the script was ending at that point, but also causing a redirect that was hiding the exception being thrown. I added a call to Session::write() just before the redirect, which allowed the exception to not be "hidden" due to page reload.

Once I saw this, it was just a matter of tracking down code that was pushing all of this extra data I did not need, and removing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top