CodeIgniter Forums
Back button and caching - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Back button and caching (/showthread.php?tid=42732)



Back button and caching - El Forum - 06-17-2011

[eluser]veledrom[/eluser]
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 $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


Back button and caching - El Forum - 06-17-2011

[eluser]osci[/eluser]
This has been answered quite many times before in these forums. Do a little search.


Back button and caching - El Forum - 06-17-2011

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


Back button and caching - El Forum - 06-17-2011

[eluser]veledrom[/eluser]
Got the answer from another forum.


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

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



Back button and caching - El Forum - 06-17-2011

[eluser]InsiteFX[/eluser]
Most broswer's sotre the likes of the back button in there history!

Look at the jQuery history plugin!

InsiteFX


Back button and caching - El Forum - 06-17-2011

[eluser]veledrom[/eluser]
Hi Lab Assistant, I even have more response from another forum!
Thanks Sr. Research Associate.

Code:
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" />
}