views:

29

answers:

1

I have created a captcha which looks like this:

<img src="/cgi-bin/rand.pl" />

The problem is that if someone navigates away from or back to the page with the captcha on it, it doesn't refresh which makes the captcha invalid (especially if they have already submitted the form before) Is there anyway to force a refresh as I suspect setting the image source with javascript wouldn't force a refresh either. The only time the image actually is refreshing is if the refresh button on the browser is used. (this isn't a problem in IE8/7,mozilla on windows XP; I just noticed it on windows 7)

+1  A: 

Set the Expires header with the current or a past HTTP datetime stamp to signal that the resource must not be cached. Example using the CGI module:

use CGI qw();
my $cgi = CGI->new;
print $cgi->header(
    -type    => 'image/png',
    -expires => '+0s',
);

__END__
Expires: Wed, 02 Jun 2010 12:13:47 GMT
Date: Wed, 02 Jun 2010 12:13:47 GMT
Content-Type: image/png

To create a standard-conforming datetime stamp on your own, use HTTP::Date or DateTime::Format::HTTP.

daxim
what about cache-control: max-age=0; so I don't have to worry about the date. Does that accomplish the same?
The document I linked to will answer this and many more questions about HTTP caching. Do read it.
daxim