CodeIgniter Forums

Full Version: Flashdata and refresh
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]mighty_falcon[/eluser]
I am having an issue with flashdata. Up to now throughout my application when I have had the need to use flashdata I have first set it in my controller and then redirected to the next one and accessed it from there without any problems.

For this one page however I need to set the flashdata in the Cart controller like this:

Code:
$this->session->set_flashdata('redirect_url', site_url('cart'));

And then link to the login page in the view of the cart controller:

Code:
<a href="&lt;?= site_url('auth/login')?&gt;">login</a>

And then be able to access the flashdata in the login controller, which I am not able to. If I place a refresh in the cart controller right after setting the flashdata it works okay.

Is there a workaround to this problem? I need to link to the login controller but cannot refresh to be able to access the flashdata...

Thanks!

El Forum

[eluser]clip[/eluser]
I think I understand you correctly.. I think this is what your looking for.

Code:
$this->session->keep_flashdata('redirect_url');

El Forum

[eluser]mighty_falcon[/eluser]
The keep_flashdata would not work really. The problem is that the flashdata seems to only be available when a refresh is done, but in my case I am just linking to the login controller and no refresh is ever done.

El Forum

[eluser]clip[/eluser]
If this is the flow of your app,
a. cart full of stuff
b. set flashdata with current link
c. click link to login (request)
------Here you should be able to access flashdata and where you would set keep_flashdata()-------
d. enter login info and submit.(request)
e. if login info is authenticated, log the user in and redirect back to a.

keep_flashdata should work, I'm not aware that it is only valid on a redirect.

El Forum

[eluser]mighty_falcon[/eluser]
That is what i thought too, but unfortunately I am not able to access the flashdata even the first time the login controller is loaded. I am doing a

Code:
print_r($this->session->flashdata('redirect_url'));


when coming to the login controller and it is empty. While if i do it with a redirect('login', 'refresh') it works okay.

Any other ideas?

Thanks for pitching in so far Smile

El Forum

[eluser]WanWizard[/eluser]
What kind of session management do you use? CI's or a third party library? If CI's, do you use the database or cookies to store the session?

Are you sure you're set_flashdata() call is executed?

El Forum

[eluser]mighty_falcon[/eluser]
I am using CIs and using cookies for now.

I am sure set_flashdata is being executed, since if i place a redirect() right below the set_flashdata line it works wokay.

El Forum

[eluser]WanWizard[/eluser]
For cookies to work they need to be send to the browser, so that they can be picked up by the next request.

In your case, with the user clicking on a link, the browser does a GET request when the user clicks the link, thus never receiving the updated cookie. When you redirect, you send a response to the browser telling it to fetch a new URL, which would deliver the cookie.

Switch to database sessions so the session data is stored server side, which solves this problem.

El Forum

[eluser]mighty_falcon[/eluser]
I just switched to using database sessions and still the same problem. Hmm I might just have to figure another way to pass the redirect_url...

El Forum

[eluser]Buso[/eluser]
I had this problem once, never knew what was going on. But it had something to do with cookies, I'm sure. Are you by chance sending a cookie there? (other than CI's one) Maybe a remember_me cookie?
Pages: 1 2