CodeIgniter Forums
flashdata won't work with redirects - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: flashdata won't work with redirects (/thread-53501.html)



flashdata won't work with redirects - El Forum - 07-26-2012

[eluser]predi[/eluser]
flashdata won't work with redirects even if keep_flashdata is used. Why?

this is the main view class:

Code:
public function index()
{
   // this end up with an empty string like "message ="
   die('message = '.$this->session->flashdata('message'));
}

public function activate()
{
   $this->session->flashdata('message', 'Activated!');
   $this->session->keep_flashdata('message');
   redirect(''); // this will redirect to the index method
}

Why not working?! I'm using db for storing sessions.
here's my config:

Code:
$config['sess_cookie_name']  = 'mysamplesess';
$config['sess_expiration']  = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'sessions';
$config['sess_match_ip']  = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300;



flashdata won't work with redirects - El Forum - 07-26-2012

[eluser]TWP Marketing[/eluser]
use set_flashdata()
Code:
$this->session->set_flashdata('item', 'value');



flashdata won't work with redirects - El Forum - 07-28-2012

[eluser]predi[/eluser]
[quote author="TWP Marketing" date="1343323633"]use set_flashdata()
Code:
$this->session->set_flashdata('item', 'value');
[/quote]

Sorry, my mistake. I was using "set_flashdata". I figured what was the problem. I've been testing the project on my localhost server, but the db i was using for session storing was on a remote server with a pretty shitty connection (3-4 sec to get mysqli connected).
So as far as i'm aware now there two solutions:
- do not use remote databases for session storage, use a local one (same sever)
- use cookies only for sessions

dunno why, will look up the "core" code to investigate that "bug" or whatever.


flashdata won't work with redirects - El Forum - 07-30-2012

[eluser]TWP Marketing[/eluser]
I certainly agree with avoiding the use of remote servers for db access.
There are some situations where it can't be done any other way, but I don't like putting my sites at the mercy of more than one server.
Hope your problem is resolved.


flashdata won't work with redirects - El Forum - 08-03-2012

[eluser]Hampti[/eluser]
Hi there,

my experience with flashdata :
when i did my first CodeIgniter project years ago flashdata worked fine. Just as i thought it was intended, and i used it a lot.

Quite some time ago it stopped working correctly and the data always displayed with delay, just one request too late.

I did some research and tried several "solutions", but none of them worked.

So i would suggest: dont bother and use userdata instead.
If you unset the userdata right after passing it to a view, it works exactly as flashdata did before.

Its a pity though, and if someone could come up with why flasdata is messed up / delayed: Please tell us =).

Best Regards,
Constantin

edit
sorry, overlooked that you solved your problem and it was a different one