0

So this is a really weird one.

I have recently discovered Code Ignitor's flash data, which is exactly what i need.

However, I am noticing that sometimes I experience issues with it. Splitting it right down to the barebones(function one does literally nothing more than this except using real data, and function two does nothing more before fetching flash data, which is why I am confident I can reduce them down to this).

controller_one :

function one()
{
  $data['foo'] = 'bar';
  $this->session->set_flashdata('extra_data', $data);
  redirect('controller_two/two');
}

controller-two :

function two()
{
  if($this->session->flashdata('extra_data'))
  {
    var_dump($this->session->flashdata('extra_data'));
  }
}

The third file is just a static page with a static link to controller_one/one say index.

Now if i go index and click the link, it will correctly redirect and dump the data - as expected.

Now - and this is where it gets weird. If I go to the index - wait 10minutes + then click the link, it redirects but the flashdata is empty(NULL).

I really don't see how waiting on a static page to click a static can affect what is happening during the redirect between the two functions - causing loss of flash data, as that flashdata isn't even set until that link is clicked and the redirect happens immediately after that in both cases.

I have also tried to var_dump($this->session->flashdata('extra_data')); die; just before the redirect, and in both cases the data is set and correct - no difference, so it must be being lost during the redirect itself - I just can't comprehend how a wait before that influences that, but it must be - somehow.

It's fairly easy for me to work around, using standard sessions or whatever, but as flash data does exactly what I want, it seems more appropriate to use this - it's just not working if the user lingers on the page before it's set.

So any theories as to why, or better yet solutions, would be greatly appreciated.

Louis M.
  • 143
  • 13
  • weird.. Flashdata should persist until the next request. That said, flashdata "lives" among regular session vars (it's only flagged differently) so it may be that your whole session data is expiring. What is your session expiration time? It could be (but honestly this is just speculation) that doing the `var_dump` counts as "the following request" and thus makes the flashdata expire. You can stand in between regular session data and flashdata in terms of lifetime by using tempdata (which is basically the same but with a custom expiration time). Have you tried that? – Javier Larroulet Mar 07 '19 at 12:20
  • other things that may have an impact here: what session driver are you using? do you have more than one (load-balanced) server or is your application running on a single server all the time? – Javier Larroulet Mar 07 '19 at 12:22
  • Single server. And the var_dump is not counting as the following reauest(i tested this). I am aware of the tempdata yes, but it's not ideal even if it may work as a workaround. Sesssion expiry is 1h, and that's not the cause because I would get logged out and end up nowhere near the requested pageif that expired.And besides, in both situations the time between setting the data and fetching it is quasi insant - it's the previous page that is sitting idle(hence it being so odd). – Louis M. Mar 07 '19 at 12:37

0 Answers0