Oh no! Our contact form is broken!

Technology Blog

(It’s fixed now, I’m pleased to say)

Having noticed we weren’t getting many enquiries through our contact form, I did a quick test this morning and to my dismay saw an error message on the CAPTCHA field, even though I’d typed it correctly. What could be going wrong?

I began to suspect the probable cause when I noticed that the CAPTCHA image in the sidebar didn’t change as I navigated around the site. Every time the form is shown a new image is supposed to be created, and that wasn’t happening.

Further investigation confirmed that the image was being cached by my browser. This meant that the form was often showing an old image instead of the one that should be there. So the letters that were shown would not match the ones the software was expecting, and hence the error.

The culprit? At my web server I had turned caching on for all images including those being generated dynamically. What I needed to do to fix the problem was to make the cache control more discriminating, so only images from actual files on disk, not those made by scripts, are cached. Obvious, when you know. Doh!

For those that might be interested, here’s the lines from our .htaccess file that caused the problem:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
</IfModule>

And here’s the new working version of the same lines:

<IfModule mod_expires.c>
<IfModule mod_header.c>

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>

# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>

# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
</IfModule>

Figure W can fix your web application problems as well as their own! Call us on 07783 386951 or use our (now working) enquiry form.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>