Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Expiring CGI pages

by legLess (Hermit)
on Mar 07, 2002 at 17:24 UTC ( [id://150060]=perlquestion: print w/replies, xml ) Need Help??

legLess has asked for the wisdom of the Perl Monks concerning the following question:

Monks ~

Ok, I thought this would be simple, but apparently not. I want to expire pages that my CGI sends to the browser. This is my current code:
print header( -type => 'text/html', -expires => 'now' );
And when called from the shell it prints, as expected:
Expires: Thu, 07 Mar 2002 17:19:12 GMT Date: Thu, 07 Mar 2002 17:19:12 GMT Content-Type: text/html; charset=ISO-8859-1
But when I run the program in a browser, it doesn't at all do what I expect. Now, maybe that's the problem: what I want is for the page to expire and, instead of showing a cached version when the user hits "Back" or "Forward," actually call and run the program again. What the browser (multiple browsers on multiple platforms) does is politely scroll back and forth through its history.

I've tried setting "-expires" to "-1d", and leaving it out entirely, with the same (zero) effect. There are other ways I can solve this problem, but cache-control seems one of the better ones. Any advice from the Monks on how to get this working?

Thanks!
--
man with no legs, inc.

Replies are listed 'Best First'.
Re: Expiring CGI pages
by dws (Chancellor) on Mar 07, 2002 at 17:35 UTC
    I want to expire pages that my CGI sends to the browser.

    I've had some luck (on some browsers) by also doing sending

    Cache-Control: no-cache Pragma: no-cache
    The Cache-Control header is supposed to be a directive to caching proxies, but some browsers seem to honor it.

      Ok, fair enough. This does basically what I want, which is generate an "expired" warning in the browser.

      However, isn't it possible to actually run the script again? An in-between option? Not just showing the history page, and not just showing a warning, but actually having the page generated again for the user? (I think /. does this.)

      EDIT
      I should add that these pages are viewed only over a secure connection (HTTPS).
      --
      man with no legs, inc.
        Take a look at this document for an in-depth explanation of caching behavior.

        I'm not sure /. actually behaves the way you imply. But the site's code is open source, so if you are really motivated you could figure out how they do it! ;-)

        My personal experience has been that caching behavior in browsers follows few rules and is a constant source of annoyances, but I wish you luck!!

Re: Expiring CGI pages
by strat (Canon) on Mar 07, 2002 at 17:33 UTC
    Maybe instead of expires the following line in the header might help you:
    <meta http-equiv="cache-control" content="no-cache">
    (Sorry, I don't know how it works with CGI.pm).

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

      No.

      Don't send anything in the body of the message that is really meant to be sent in the headers. The "meta http-equivalent" is meant only for those (hopefully rare) situtations where a document content needs to specify some meta instructions. Since the original question was clearly in the context of a CGI script, where you do in fact control the headers, the answer is completely inappropriate.

      {sigh}

      -- Randal L. Schwartz, Perl hacker

        I wrote: Maybe instead of expires the following line in the header might help you:

        I didn't write: put this line in the body, did I?

        If I really did, then sorry for my bad english. This was not intended by me.

        Best regards,
        perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Re: Expiring CGI pages
by perrin (Chancellor) on Mar 07, 2002 at 20:20 UTC
    You can't expect people to have their computer's clocks set correctly. If you want things to expire immediately, set an expiration date some time in 1971. Most people at least have the decade right.
      Ok, you'll have to explain this to me, unless it's humor :)

      If the server sends the current time with the header, and page is set to expire at that exact time, how does the client's clock even come into it?
      --
      man with no legs, inc.
        The server says "this expires at 3:27". How does the client machine know when it's 3:27? It checks its own clock. That clock can be off. Way off. This kind of problem happens any time you have two machines talking about things happening at exact times but their clocks are not synchronized.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://150060]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found