CodeIgniter Forums

Full Version: Using flashdata after redirect?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I humbly request some assistance.

I am setting some flashdata just prior to using a "redirect" and the flashdata is not saving/showing up after the redirect.

My code is as follows:

PHP Code:
$this->session->set_flashdata('message''test');
redirect('login''refresh'); 

On the login page though ("login" controller function), the flashdata isn't showing up. Here are some things to note:
  1. Everywhere else I use flashdata works fine (not in conjunction with redirect)
  2. My sessions and cookies all are working fine (apart from this issue)
  3. I've tried using keep_flashdata() everywhere I can think to put it and it doesn't help
  4. I'm not destroying any sessions prior to redirecting
  5. I'm using CodeIgniter v3.0.3 (latest)
  6. I thought maybe the "redirect" was taking more than one request, but am unsure how to test that? It should only be one request.
Any ideas or possible solutions would be greatly appreciated.

Thanks!
I'm also having the same problem, but in my situation is after logout progress which is in my code
$this->sessions->sess_destroy(); $this->session->set_flashdata('message','Successfully logout'); redirect('login'); Solve the problem by add sess_regenerate() after sess_destroy()
Yes I thought that could have been the issue, but I'm not destroying any sessions, so the flashdata should be intact.
(11-17-2015, 01:08 AM)JayAdra Wrote: [ -> ]Yes I thought that could have been the issue, but I'm not destroying any sessions, so the flashdata should be intact.

Try removing this 'refresh' in your redirect I think that is why flash data not showing.

and then on login view

<?php if ($this->session->flashdata('message')) {?>
<?php echo $this->session->flashdata('message');?>
<?php }?>
I forgot to mention that I also tried that - it didn't help. Thanks for the suggestion though.
Try adding in the login constructor and see if that works.
PHP Code:
$this->session->keep_flashdata('message'); 

Also remove 'refresh' from the redirect.
Hi

Please check "$this->load->library('session');" writing or not in controller (log out) action
(11-17-2015, 04:41 AM)Sentro Wrote: [ -> ]Try adding in the login constructor and see if that works.
PHP Code:
$this->session->keep_flashdata('message'); 

Also remove 'refresh' from the redirect.

Yeah I did try this, as I mentioned in point 3 - I have tried it again now (and removed refresh from the redirect) and it's still not working.

Appreciate the suggestion though.
Have you tried
PHP Code:
var_dump($_SESSION); 

After setting it?

PHP Code:
$this->session->set_flashdata('message''test');
var_dump($_SESSION);
exit;
redirect('login''refresh'); 

Is the message available in the $_SESSION array?
Is there an AJAX request? Maybe it somehow captures and clears the flashdata before the redirection?

A side note:
When AJAX is called by jQuery
headers["X-Requested-With"] = "XMLHttpRequest";
is done automatically, but in other cases this header might be forgotten.
Pages: 1 2