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

Hi Monks
I'm have a perl backed web site that does authentication etc, but I have a issue I was wanting some advice on.

If I log in as user A go to a node all works as expected.
i.e. http://www.mysite.com/cgi-bin/node.cgi?id=101
Hello User A, blah blah blah


Then I log out user A and log in user B and goto the same page as the first user (the page was actually owned by user A, I just paste the link), it displays the same info, saying that its user A logged as before not user B.
i.e.
Hello User A, blah blah blah

instead of
Hello User B, not your page, bugger off

Now if you shift refresh the browser it works, so I'm thinking that the page must be cached.... How do I get around the pages being cached? I was thinking maybe it might have been because of my Content-type being 'text/html' and maybe that means 'ok there must not be any dynamic content so send the cached copy', but now I'm not so sure because if it ran the script to get to the header it would have displayed the rest correctly.
Any thoughts...?

Regards Paul

Replies are listed 'Best First'.
Re: Web Page Caching
by fmerges (Chaplain) on Jun 29, 2005 at 22:57 UTC

    Hi Paul,

    Take a look at http://www.i18nguy.com/markup/metatags.html here you see some useful META tags you can use in your pages...

    But, one thing that you don't say is how are you making the login in and out...

    For example if you are running an Apache mod_perl enabled webserver and you use Apache::Registry you must code your cgi's with some things in mind see http://perl.apache.org/docs/1.0/guide/porting.html.

    If you can't or won't change it so that it works with Apache::Registry, you can use Apache::PerlRun instead...

    But as I said... more info would be great, to give a more certain answer of what is happening. ;-)

    Regards,

    |fire| at irc
      Thanks for the reply fmerges,
      A previous node (469478) I posted talks a bit about how I'm authenticating. I'm using CGI::Session to track state with cookies and accessing encrypted passwords via DBI.
      I haven't looked into the Apache modules yet, but might track them down. There is always more than one way to do it, but is one of these methods more generally accepted as the way to do these things more than another?

      Regards Paul
Re: Web Page Caching
by srdst13 (Pilgrim) on Jun 29, 2005 at 23:03 UTC
    You might want to take a look at these links:
    1 and 2. These have to do with setting html meta tags to control caching behavior. I think that is probably what you want....

    Sean
      srdst13,
      Thanks for the links, I applied the tags as follows at the top and bottom of the page and all is well, no more caching. =)
      <HEAD> <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"> <META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache\"> <META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\"> </HEAD>


      Regards Paul
      Hi Sean
      An extension of the question I asked I hope you might be able to answer. I have the no-caching working with html pages which works good, but am having trouble with images.
      All of my 'nodes' come from a database and they have types, if its a text type node its displayed and the appropriate no-caching tags added as per previous advice from the other posts. If however the node is an image I set the content to 'image/jpeg' or whatever it is and then dump the data. The picture comes through fine, however this prevents me from using the cache tags? This means that if a user logs in from a browser and looks at page xyz which is an image and they have privs to do so they can, and after they log out if someone else looks at the image (without have closed the browser) it is still viewable (unless they shift-refresh). Do you no a way around this?
      Is it possible to send something like...
      Content type: html/text ... HTML here (turn off caching etc) ... Content type: image/jpeg ... image data ... Content type: html/text ... more HTML here ...
      Can you do this from one .....send..? is there a dynamic image content type I can use, so it will always re-request the content?

      Regards Paul
Re: Web Page Caching
by Adrade (Pilgrim) on Jun 30, 2005 at 05:33 UTC
    My intuition is that you're using mod_perl and you're running into a closure, as I had similar problems with mod_perl. If you are using mod_perl, be sure you use strict; and that you pass everything to any subroutine you employ, including blessed references. Anything you don't pass will maintain a life of its own (in a sense) within the subroutine, so be careful.

    Again, as said, use Pragma or Cache-Control to prevent caching, either in HTML as: <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> or as an HTTP header: Pragma: no-cache - there's also the newer (and probably better, ie. HTTP 1.1) Cache-Control: no-cache header that can also be smushed into a meta tag: <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">. I'd use both as HTTP headers if I wanted to prevent caching.

    Hope it helps,

      -Adam

    --
    Impossible! The Remonster can only be killed by stabbing him in the heart with the ancient bone saber of Zumakalis!