Welcome Guest, Not a member yet? Register   Sign In
Session Destroy and Flashdata
#1

(This post was last modified: 10-30-2021, 03:18 AM by donpwinston.)

When I execute a 
Code:
$session->destroy();
$session->setFlashdata('msg', 'Hello');
return()->redirect()->to('/');

The flash data is not available on the redirected page. Why?
Simpler is always better
Reply
#2

Because you desroyed the session you need to recreate the session again first.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-02-2021, 03:50 AM by donpwinston.)

(10-31-2021, 01:16 AM)InsiteFX Wrote: Because you desroyed the session you need to recreate the session again first.

OK, I get it. It's not created again until the constructor of the redirected page is executed.
Simpler is always better
Reply
#4

(This post was last modified: 10-31-2021, 09:34 PM by manager.)

(10-31-2021, 12:51 PM)donpwinston Wrote:
(10-31-2021, 01:16 AM)InsiteFX Wrote: Because you desroyed the session you need to recreate the session again first.

But my redirect's page controller creates the session in the constructor.
You must start the session BEFORE setFlashdata, not from your redirected page, because at this time there is no session.

just add session_start() right after destroying it (and before setFlashdata())
Reply




Theme © iAndrew 2016 - Forum software by © MyBB