FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Please evaluate my cache-control & pragma etc. code
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Please evaluate my cache-control & pragma etc. code [message #182518] Fri, 09 August 2013 14:22 Go to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
Mainly I'm interested in whether it's considered workable/usable.
It doesn't seem to be working on my win 7 XAMPP PHP5.3 Local Server.
The data still seems to exist if/when I "go back" to the preceding page
of an e-mail form.

<?php
session_start();
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0

TIA,

Twayne`
Re: Please evaluate my cache-control & pragma etc. code [message #182519 is a reply to message #182518] Fri, 09 August 2013 16:57 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 09/08/13 20:22, Twayne wrote:
> Mainly I'm interested in whether it's considered workable/usable.
> It doesn't seem to be working on my win 7 XAMPP PHP5.3 Local Server.
> The data still seems to exist if/when I "go back" to the preceding page
> of an e-mail form.

It's all up to the client if it will follow cache rules from the server
or not.


--

//Aho
Re: Please evaluate my cache-control & pragma etc. code [message #182520 is a reply to message #182519] Fri, 09 August 2013 19:12 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 2013-08-09 4:57 PM, J.O. Aho wrote:
> On 09/08/13 20:22, Twayne wrote:
>> Mainly I'm interested in whether it's considered workable/usable.
>> It doesn't seem to be working on my win 7 XAMPP PHP5.3 Local Server.
>> The data still seems to exist if/when I "go back" to the preceding page
>> of an e-mail form.
>
> It's all up to the client if it will follow cache rules from the server
> or not.
>
>

Thanks, that's a good point!

Magically, for whatever reason, it started working again after a Cold
Boot; Windows in all its glory, I guess. :(

Cheers,
Re: Please evaluate my cache-control & pragma etc. code [message #182522 is a reply to message #182518] Sat, 10 August 2013 04:49 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 09/08/13 19:22, Twayne wrote:
> Mainly I'm interested in whether it's considered workable/usable.
> It doesn't seem to be working on my win 7 XAMPP PHP5.3 Local
> Server. The data still seems to exist if/when I "go back" to the
> preceding page of an e-mail form.
>
> <?php
> session_start();
> header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
> header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
> header('Pragma: no-cache'); //HTTP/1.0
>
> TIA,
>
> Twayne`
>
my limited experience suggests that browser caching is more affected by
the etag.
I have been writing a framework that serves all pages /objects from a
database ( for reasons of security and control), and found that in
general browsers don't really honor cache control, but they do honor etags.
I think proxies tend to honor cxahche control more.

The browsers tend to say 'ive got a copy, do I need a new one?' and
actually ask, using the etag.

I found that out looking at my log files on pages with multiple images
under constant rerfreshing. The logs were full of 304 responses, but
there were always as many of those as the page had images for a given
page load.

The code that checks the etag is here - it really does reduce server
load if you want to not resend data that's already been sent

// check if etag matches if none match request headers
function check_etag($etag)
{
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
strstr($_SERVER['HTTP_IF_NONE_MATCH'],$etag))
{
header('HTTP/1.0 304 Not Modified');
exit();
}
}
This is a handy way to encourage browsers not to re-download static pages.

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
Re: Please evaluate my cache-control & pragma etc. code [message #182525 is a reply to message #182518] Sat, 10 August 2013 11:19 Go to previous messageGo to next message
Fiver is currently offline  Fiver
Messages: 35
Registered: July 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On 2013-08-09 20:22, Twayne wrote:
> header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');

2005-07-01 was a Friday, not a Sunday.

5er
Re: Please evaluate my cache-control & pragma etc. code [message #182526 is a reply to message #182525] Sat, 10 August 2013 13:17 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 2013-08-10 11:19 AM, Fiver wrote:
> On 2013-08-09 20:22, Twayne wrote:
>> header('Expires: Sun, 01 Jul 2005 00:00:00 GMT')

;
>
> 2005-07-01 was a Friday, not a Sunday.
>
> 5er
>

Hmm, good catch: Does it really matter I wonder? Maybe that explains why
it did/didn't and then did appear to work in testing.

Thanks & Regards,

Twayne`
Re: Please evaluate my cache-control & pragma etc. code [message #182527 is a reply to message #182522] Sat, 10 August 2013 13:21 Go to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 2013-08-10 4:49 AM, The Natural Philosopher wrote:
> On 09/08/13 19:22, Twayne wrote:
....
>> <?php
>> session_start();
>> header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
>> header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
>> header('Pragma: no-cache'); //HTTP/1.0

....

> my limited experience suggests that browser caching is more affected by
> the etag.
> I have been writing a framework that serves all pages /objects from a
> database ( for reasons of security and control), and found that in
> general browsers don't really honor cache control, but they do honor etags.
> I think proxies tend to honor cxahche control more.
>
> The browsers tend to say 'ive got a copy, do I need a new one?' and
> actually ask, using the etag.
>
> I found that out looking at my log files on pages with multiple images
> under constant rerfreshing. The logs were full of 304 responses, but
> there were always as many of those as the page had images for a given
> page load.
>
> The code that checks the etag is here - it really does reduce server
> load if you want to not resend data that's already been sent
>
> // check if etag matches if none match request headers
> function check_etag($etag)
> {
> if(isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
> strstr($_SERVER['HTTP_IF_NONE_MATCH'],$etag))
> {
> header('HTTP/1.0 304 Not Modified');
> exit();
> }
> }
> This is a handy way to encourage browsers not to re-download static pages.
>

Which is precisely what I want to do, actually. I'll look into that a
bit further and try it! Thanks much for the alternative.

Best regards,

Twayne`
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Re: Counter reset or not?
Next Topic: How to create a user friendly URL with parameters?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Oct 18 08:55:33 EDT 2017

Total time taken to generate the page: 0.00687 seconds