简体   繁体   English

为什么在fuelPHP中重定向后会话数据会丢失?

[英]Why is session data lost after redirect in fuelPHP?

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 该域处理数据,并回发到控制器A
  3. controller A processes returned data, and sets flash session vars 控制器A处理返回的数据,并设置Flash会话变量
  4. controller A redirects to controller B 控制器A重定向到控制器B
  5. session values set in controller A are lost. 控制器A中设置的会话值丢失。

Now, I have noticed that if I eliminate step 4; 现在,我注意到如果取消步骤4, the session values are not lost. 会话值不会丢失。 It is only happening after calling Response::redirect(). 它仅在调用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.): 以下是控制器A的后处理程序中的相关代码(在这种情况下,$ vars设置为Input :: post(); renew()方法对另一个API进行了肥皂调用,并返回响应数据。):

$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(): 这是方法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: 最后,这是控制器B中访问会话数据的代码:

$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. 我在before()方法中设置的所有会话数据都会保留。

I'm very stumped on this one. 我对此很困惑。 Any ideas why my session data is lost? 有什么想法会丢失我的会话数据吗?

As it turned out, the core issue was that my session cookie was exceeding 4kb. 事实证明,核心问题是我的会话cookie超过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. 发生的事情是,当我调用Response :: redirect()时,脚本已在该点结束,但还会导致重定向,从而隐藏了抛出的异常。 I added a call to Session::write() just before the redirect, which allowed the exception to not be "hidden" due to page reload. 我在重定向之前添加了对Session :: write()的调用,该调用使异常不会由于页面重载而被“隐藏”。

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. 一旦看到此信息,只需跟踪代码即可推送我不需要的所有这些额外数据,然后将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM