By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Prevent Safari from caching using header()

P: n/a
Hello PHP group

I'm trying to prevent Safari from caching pages (e.g. private pages),
so it is not possible to view them when hitting the back button.

I tried it as described on Apple's developer site:
http://developer.apple.com/internet/...q.html#anchor5

using

// PHP example - include at the top of your pages
<? php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //
always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-
age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>

However, this does not work.

Does anyone know a reliable solution?

Many thanks.
Aug 13 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Werschinger wrote:
Hello PHP group

I'm trying to prevent Safari from caching pages (e.g. private pages),
so it is not possible to view them when hitting the back button.

I tried it as described on Apple's developer site:
http://developer.apple.com/internet/...q.html#anchor5

using

// PHP example - include at the top of your pages
<? php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //
always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-
age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>

However, this does not work.

Does anyone know a reliable solution?

Many thanks.
You can't guarantee a page won't be cached - you can only recommend it.
Servers along the path as well as the browser can still cache the
information.

Try alt.html (hint - although you are using the header() function, the
problem is the headers themselves, not php).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 13 '08 #2

P: n/a
In our last episode,
<43**********************************@v57g2000hse. googlegroups.com>,
the lovely and talented Werschinger
broadcast on comp.lang.php:
Hello PHP group
I'm trying to prevent Safari from caching pages (e.g. private pages),
so it is not possible to view them when hitting the back button.
You cannot force this in HTML, and so you cannot force it in php,
because php is (or should be) HTML when it reaches the browser.
Depending upon what you mean by 'private pages,' this would seem to be a
browser question. In some browsers you must reduce memory and disc cache to
0 --- others have a more convenient check box for 'never use cached pages.'
Most modern browsers are fairly good about this; some older ones would
load new html but not reload linked css, which was a headache in
development. Consult your browser documentation or an appropriate browser
group.

--
Lars Eighner <http://larseighner.com/us****@larseighner.com
God is REAL, unless explicitly declared INTEGER.
Aug 13 '08 #3

P: n/a
Thanks for everybody's input.

I understand I cannot force it, but I've seen it work on other sites,
e.g. banking sites.

"Private" pages would be any pages you don't want others to see, like
your email inbox for instance.

I'm just looking for a solution for Safari in case of public or shared
computer usage. For IE6, 7 and Firefox, the mentioned solution works.

I've posted it in alt.html as suggested by Jerry. Maybe I should post
in a Safari group as well.
Aug 13 '08 #4

P: n/a
On Aug 13, 9:54*am, Werschinger <dinko.ve...@googlemail.comwrote:
Thanks for everybody's input.

I understand I cannot force it, but I've seen it work on other sites,
e.g. banking sites.
There's the best place to start, look at the page source of those
pages and see if you see anything obviously different.

Aug 13 '08 #5

P: n/a
How about forcing a session, then destroying it when they are done or
after a certain time limit.
Aug 13 '08 #6

P: n/a
..oO(la***@portcommodore.com)
>On Aug 13, 9:54*am, Werschinger <dinko.ve...@googlemail.comwrote:
>Thanks for everybody's input.

I understand I cannot force it, but I've seen it work on other sites,
e.g. banking sites.

There's the best place to start, look at the page source of those
pages and see if you see anything obviously different.
The HTTP response headers might be a better place to start.

Micha
Aug 13 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.