Welcome Guest, Not a member yet? Register   Sign In
Back button and caching


I have a problem related to BACK button in browsers.

In very first page my basket shows "0 item". I go to next page to add one item to basket $this->cart->insert($data) and it shows $this->cart->contents() "1 item" in current page. If I hit BACK button in browser to go back to very first page again, the basket shows "0 item" although the basket has actually "1 item" in it. So, how do I solve this problem? Is it related to cache or refreshing etc. I read a bit about caching but I lost myself in it also not sure it is to do with it anyway.

Is there anything I can do with CI functions? Placing a code on top of the page or caching bits....

Thanks for advance

This has been answered quite many times before in these forums. Do a little search.

To be honest with you, I did some search and left same message to other forms but no luck.

Got the answer from another forum.

header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");

$this->load->view('template.php', $data);

Most broswer's sotre the likes of the back button in there history!

Look at the jQuery history plugin!


Hi Lab Assistant, I even have more response from another forum!
Thanks Sr. Research Associate.

public function stop_caching()
  $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  $this->output->set_header("Pragma: no-cache");
  //** PHP Style
  //header("Cache-Control: no-cache, no-store, must-revalidate, post-check=0, pre-check=0");
  //header("Pragma: no-cache");
  //** HTML Style
  //<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, post-check=0, pre-check=0" />
  //<meta http-equiv="Pragma" content="no-cache" />

Theme © iAndrew 2016 - Forum software by © MyBB