Processing
 

Flashdata not getting cleared in Codeigniter

17/09/2013 09:44#1

Sachin

Member

Joined at: 12 months ago

Post: 22

Thank: 0

Thanked: 0

I am using Codeigniter 2.1.4 and I have facing some issues with flashdata. When I successfully submit record I can display the flashdata message. But if go to the other page from the page where flashdata message was displayed and then go back to previous page using browser back button it shows me flashdata message again.
How to clear flashdata message once it used? I think its not the flashdata issue its cache problem. I am confused why this is happening. If its cache issue then how to remove it?

Below is code I have used,

//In the manage of controller $this->session->set_flashdata('message', "Record updated successfully.");  // In the view of controller $data['message'] = $this->session->flashdata('message');  // In the view page echo $message; 
17/09/2013 09:45Top#2

Nabil

Member

Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

Flash disappears only after next refresh

17/09/2013 09:50Top#3

ABorty

Member

Joined at: 10 months ago

Post: 2

Thank: 0

Thanked: 0

your code in controller is right

//In the manage of controller $this->session->set_flashdata('message', "Record updated successfully."); redirect('controller_name/function_name','refresh'); 

now in view use like this

if($this->session->flashdata('message')){echo $this->session->flashdata('message');} 

hope it will work

17/09/2013 09:48Top#4

Nil'z

Member

Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

$this->session->set_flashdata('message', "Record updated successfully."); 

After setting the flashdata redirect to some function or to the same function.

01/03/2014 17:42Top#5

Wasim

Member

Joined at: 12 months ago

Post: 23

Thank: 0

Thanked: 0

You must redirect the page somewhere after $this->session->set_flash('item','value');

Example:

if ($this->form_validation->run() == FALSE){     $this->session->set_flashdata('error',validation_errors());     redirect(base_url().'user/login'); } else{     $this->session->set_flashdata('success','Thank you');     redirect(base_url().'user/login'); } 

Usually developer make a mistake when they submit data to same page. They set flash data but forget to redirect.

06/07/2016 17:28Top#6

Hemantha

Member

Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

If you refresh in the same controller function the flashdata won't be deleted.Also going back and forth in the browser does't affect the flashdata. to clear the flashdata redirect to another controller function and it will work.

Similar articles

Chrome, THREE.js: Cross-origin image load denied

5 years ago - Reply: 5 - Views: 271

Prevent Google Chrome Log XMLHttpRequest

3 years ago - Reply: 5 - Views: 277

How can I include ChromeDriver in a JAR?

3 years ago - Reply: 3 - Views: 83

Chrome geolocation not working on any site

3 years ago - Reply: 1 - Views: 49

wrong borders' width in android browser

3 years ago - Reply: 4 - Views: 207

Uncaught SyntaxError: Unexpected token < On Chrome

3 years ago - Reply: 10 - Views: 472

Flashdata not getting cleared in Codeigniter

4 years ago - Reply: 5 - Views: 58

Illegal access Javascript error in Chrome

3 years ago - Reply: 1 - Views: 53

ng-repeat not updating in Chrome

3 years ago - Reply: 1 - Views: 82

Applying border to a checkbox in Chrome

4 years ago - Reply: 2 - Views: 119

open browser plugin using access vba

3 years ago - Reply: 1 - Views: 26

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re