Cache Form Data But Not CAPTCHA Image

I did a search here and using search engines and haven’t found a solution to my problem.

I have a form with a CAPTCHA on it which visitors can use to input data to conduct a search. The original problem was that when the I reached the search results page and hit the browser’s back button, the form data was gone. I found two solutions:


header('Cache-control: private');

header('Cache-Control: max-age=3600');

Both methods work fine to cache the form data (I use only one header, not both). The problem is that the CAPTCHA image is also cached. I do not want that.

Is there a solution using a PHP header I can use to allow caching of the form data but require the CAPTCHA image to be refreshed?

If there is no way to do that using a header in PHP, is there a way to refresh the CAPTCHA when the back button is pressed using Javascript?

Any ideas? Thanks for your help. :slight_smile:

it depends on how you generate your captcha image.

I have my own php script which outputs a jpg captcha image and in my html I have

<img id="imgCaptcha" alt="Captcha image" src="getCaptchaImg.php?action=new" />

and I get a new captcha image every time I click the browser’s back or forward buttons.

I don’t need to add anything to the headers to make sure I get a new captcha image on each page load.