Support Forums

Development Forum

prevent visitors pages from being cached


You must be signed-in to post.

AuthorSubject
  Page: 1
joshua_howell

Avatar for joshua_howell
Subject: prevent visitors pages from being cachedQuote this post in your reply
I am having issues with cached pages displaying old data so i would like to prevent visitors browsers from caching pages from "server side".

Apparently the code below should do this, can anyone forsee any problems with using this code and is there asingle file i can add this to so every single ATutor page will inherit it?

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
$today = date("D, d M Y H:i:s T"); // todays date
header("Expires: ". $today.""); // Date in the past
?>
Posted: 2009-08-17 20:41:14
IndieRect

Avatar for IndieRect
Subject: Re: prevent visitors pages from being cachedQuote this post in your reply
Hi,

You can try putting it to include/header.inc.php, somewhere near the top.
There're other places of course, just make sure it gets output before any HTML code does.
Posted: 2009-08-18 02:19:36
joshua_howell

Avatar for joshua_howell
Subject: Re: prevent visitors pages from being cachedQuote this post in your reply
Thanks for the reply IndieRect.

I tried adding the following code to both; include/header.inc.php and themes/default/include/header.tmpl.php but neither appeared to work.

header("Cache-Control: no-cache");
header("Expires: -1");

I there a way to check if the code has been added, by checking the source for example?
Posted: 2009-08-20 20:18:34
IndieRect

Avatar for IndieRect
Subject: Re: prevent visitors pages from being cachedQuote this post in your reply
You are welcome.
HTTP headers (which is what you set by that code) are not part of HTML content, so you can't view them as you would normally view the page source.

You can install Firebug add-on for Firefox and see them under the Net tab. Google for details.
Posted: 2009-08-21 04:07:08
joshua_howell

Avatar for joshua_howell
Subject: Re: prevent visitors pages from being cachedQuote this post in your reply
Well I couldn't get the PHP code to work so i ended up addeding some HTML meta tags and they appear to have stopped caching. In case anyone wants to know the code is;

<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />

I added those lines of HTML to the themes/*seleceted theme*/include/header.tmpl.php
Posted: 2009-08-21 19:26:37
 Page: 1

You must be signed-in to post.