Welcome Guest, Not a member yet? Register   Sign In
flashdata not cleared

According to the user manual, it says flashdata are automatically cleared.

However it does not disappear in the following code. It shows "Invalid email. Please try again!" always.

How long flash data keep it data? Is it for 5 min as a default like session data?



class Welcome extends Controller {
  function  __construct(){
function index(){
    $data['title'] = "Welcome to Claudia's Kids";
function subscribe(){
      if ($this->input->post('email')){
        if (!valid_email($this->input->post('email'))){
            $this->session->set_flashdata('subscribe_msg', 'Invalid email. Please try again!');
        // $this->MSubscribers->createSubscriber();
        $this->session->set_flashdata('subscribe_msg', 'Thanks for subscribing!');
        $this->session->set_flashdata('subscribe_msg', "You did not fill out the form!");


if ($this->session->flashdata('subscribe_msg')){
    echo "<div class='message'>";
    echo $this->session->flashdata('subscribe_msg');
    echo "</div>";
echo form_open("welcome/subscribe");
echo form_fieldset('Subscribe To Our Newsletter');
$data = array('name'=>'name', 'id' => 'name','size'=>'25');
echo "<p><label for='name'>Name</label><br/>";
echo form_input($data) . "</p>";
$data = array('name'=>'email', 'id' => 'email', 'size'=>'25');
echo "<p><label for='email'>Email</label><br/>";
echo form_input($data) . "</p>";
echo form_submit("submit","subscribe");
echo form_fieldset_close();
echo form_close();

Flash data is is not cleared after a specific time. I mean there's no time limit for it. It's cleared when you consume it once. On next page request it will be gone.

This code is from the book Professional CodeIgniter. I think you must compare the above code again with the code provided in the book. Or you can download the complete source code for the book from wrox website. Here's the link:


Thanks for your reply, iFadey.

Yes, the code is from the book you mentioned.

Can you think of anything why the flashdata does not disappear?

Okies. I looked the code in detail. The problem is simple.
You are using caching here.


Actually the flashdata is removed but you have cached the page for 30 min. So it will keep showing you the old page for about 30 min. If you remove caching here, flashdata will be not be displayed again n again.
Caching is very imp for performance but use it with care because sometimes it makes debugging difficult. Again I am not saying that don't use caching. Use caching but with care specially on pages which you think will not change frequently and pages which perform heavy database operations.

Thanks iFadey.

Appreciate it.

Your welcome Smile

Theme © iAndrew 2016 - Forum software by © MyBB