Stop page from caching in bootstrap PHP page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mursaleen
Forum Newbie
Posts: 2
Joined: Sun Aug 17, 2014 7:20 am

Stop page from caching in bootstrap PHP page

Post by mursaleen »

I'm working on php application which contains a refresh button. On clicking I want to reload the page and get fresh information from server for the table.

I have used php headers:

Code: Select all

  
    header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
As well as following meta tags

Code: Select all

    <meta http-equiv="expires" content="-1"/>
    <meta http-equiv="pragma" content="no-cache" />
to stop the page to cache.

And I'm using

Code: Select all

    location.reload(true);
to reload the page. Its working fine in Firefox. But no result in chrome and ie.

For this application I'm using bootstrap based theme.

Any help in this regard will be appreciated as I have done every thing I found out there.

Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Stop page from caching in bootstrap PHP page

Post by requinix »

Typically you don't have to do anything to prevent caching. Neither PHP nor your server will sending caching information unless told to.

So, "no result" means... it's cached? Does Chrome explicitly say (in the Network tab of the inspector thing) that it is retrieving the page "from cache"?
mursaleen
Forum Newbie
Posts: 2
Joined: Sun Aug 17, 2014 7:20 am

Re: Stop page from caching in bootstrap PHP page

Post by mursaleen »

Over there in status column on pressing refresh button I'm getting status "304 not modified" (for most of the stuff) else when pressing ctrl + F5 over there status is "200 OK" that is when new data is fetched from data base.

Is there any straight away method in network tab to see if its being cached or not or this is what you were asking?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Stop page from caching in bootstrap PHP page

Post by requinix »

The 304 Not Modified is one way caching happens. For the one I was thinking you'd see (easily) a "from cache" message.

304 means the browser went to your server for information and the server said it was not modified. Your code is actually telling the browser to do its half, but the 304 is coming from the server and that's not in the code you posted. Quite rare to see it in code, actually.

Does your server have any sort of caching thing enabled? What happens if you add an

Code: Select all

echo time();
somewhere in your code, without modifying anything else?
Post Reply