Welcome Guest, Not a member yet? Register   Sign In
Using flashdata after redirect?
#1

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!
Reply
#2

(This post was last modified: 11-17-2015, 01:05 AM by arma7x.)

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()
Keep calm.
Reply
#3

Yes I thought that could have been the issue, but I'm not destroying any sessions, so the flashdata should be intact.
Reply
#4

(This post was last modified: 11-17-2015, 01:59 AM by wolfgang1983.)

(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 }?>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#5

I forgot to mention that I also tried that - it didn't help. Thanks for the suggestion though.
Reply
#6

Try adding in the login constructor and see if that works.
PHP Code:
$this->session->keep_flashdata('message'); 

Also remove 'refresh' from the redirect.
"The Most Important Thing In Life Is Showing Up"
"I Just Had A Bad Day"
"We'll Be Back"
"Further Beyond"
Reply
#7

Hi

Please check "$this->load->library('session');" writing or not in controller (log out) action
Reply
#8

(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.
Reply
#9

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?
Reply
#10

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB