Force No Cache on a Webpage

by Brett on November 6, 2006

Sometimes it is usefull to force a web page to not be cached. One example where this could be used is on a form that takes credit card information. Once the user submits their data you may not want someone to be able to hit the back button and be able to view the users credit card information. Microsoft has an article explaining how to force the browser to not cache the page but when I tried their method it did not work. Instead with a little trial and error I came up with the following solution:

In ASP (vbscript):
Response.AddHeader "Expires", "Mon, 21 Jul 1979 01:00:00 GMT"
Response.AddHeader "Cache-Control", "no-store, no-cache, must-revalidate" ' HTTP/1.1
Response.AddHeader "Cache-Control", "post-check=0, pre-check=0" ' HTTP/1.1
Response.AddHeader "Pragma", "no-cache" ' HTTP/1.0

header("Expires: Mon, 21 Jul 1979 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0

Previous post:

Next post: