Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

CGI how to force browser reload

by cormanaz (Deacon)
on Jan 17, 2006 at 13:51 UTC ( [id://523738]=perlquestion: print w/replies, xml ) Need Help??

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

Howdy Monks. I have a script running on Apache that uses mod CGI to generate some static content files, then redirects the browser to an index page for them. It works fine.

Embedded on index this page I have a form with a set of checkboxes for dismissing some alerts set up in the system. When this form is submitted it calls a different script, also using mod CGI, that updates the database to reflect the dismissed items. That works great too.

The problem is that when I invoke the redirect method in this second script the browser doesn't reload the page to reflect the now-dismissed items. If I close and reopen the browser to force a reload, the updated list shows like it should.

So my question is: How can I get mod CGI to force the browser to reload the page?

TIA...Steve

Replies are listed 'Best First'.
Re: CGI how to force browser reload
by beachbum (Beadle) on Jan 17, 2006 at 15:53 UTC

    You could try a couple things....
    <META HTTP-EQUIV="expires" CONTENT="0"> or
    <META NAME="expires" CONTENT="0">
    is designed to force the browser to reload the page at every visit.

    If that fails, you could try using an incremented GET value to change the url each visit... something like
    http://your_Url.com/page.html?1137513119 (or whatever the current time is.)

      Those META tags will often, but not always, be respected. No agent is forced to respect them to be compliant with HTTP standards. Better to include these in the HTTP header directly, right by your 'Content-type' line. If you are using CGI::Simple or similar (and you really should be):

      print $cgi->header( -expires => 0, -nph => 1, -type => 'text/html' );

      If you aren't using one of the CGI modules (again, you probably should be), you can also do:

      print "Expires: 0\n"; # Expire immediately print "Pragma: no-cache\n"; # Work as NPH print "Content-type: text/html\n\n"; # <- mentioned as context

      Any valid HTTP/1.1 (or higher) client will respect these headers as expiring in the past, and therefore require a reload the next time the page is viewed.

      <-radiant.matrix->
      A collection of thoughts and links from the minds of geeks
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet
Re: CGI how to force browser reload
by Sioln (Sexton) on Jan 17, 2006 at 14:30 UTC
Re: CGI how to force browser reload
by john_oshea (Priest) on Jan 17, 2006 at 21:50 UTC

    For a somewhat different approach to the existing answers, you could use CGI::Ajax or an equivalent to dynamically update sections of your existing page without actually having to reload the page as a whole. You'd need to ensure that Javascript is enabled for your clients though, or have a fallback to a non-Javascript-dependent method.

Re: CGI how to force browser reload
by valdez (Monsignor) on Jan 17, 2006 at 18:13 UTC
      For the record, I did try Super Search (as I always do before posting a query). I did not try with those keywords, and of course that is the problem with keyword searches.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found