Hi,

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 and it shows "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.

Thanks for advance

Recommended Answers

All 4 Replies

If you hit F5, your page will get the latest details. Generally, this behavior is what you want and you shouldn't mess with this - in my opinion. Especially if your site is visited by users that pay for data (such as phone users) you want the back button to not cause a refresh.

I know F5 but I wonder if I have to put extra code to read everything from zero.

You can, but I recommend you not to. The expected result of the back button is bringing the browser back to a previous state, not reloading the last visited page.

There we go. I worked out. I hope it helps others as well.

public function stop_caching()
{
  // These will stop caching otherwise "Back" button on browsers will display unupdated content
		
  //** CI Style
  $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" />
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.