More Free Resources

A good way to avoid automatic form submissions when creating a web form is to add some kind of verification. One of the best ways is to use an image verification, called also captcha. What it does is to dynamically create an image with a random string displayed on it. Then visitor is asked to type that string in a text field and once the form is submitted it checks if the string on the image matches the one inputted by the user. Because there is no easy way to read a text from an image (image recognition) this is a good way to protect your web forms from spammers.
For doing this CAPTCHA I would suggest using a session variable where you store the string generated and displayed on that dynamically generated image.

Save this code in a file called captcha.php. What this script does is to generate a random number from 10000 to 99999 and then assign it to $_SESSION['vercode']. Then it generates a 25x65 pixels image with black background and white text using size 14. So if you upload that captcha.php file on your web site and open http://www.site.com/captcha.php you will see an image displaying random integer. You will receive a new random integer every time you refresh that page.

great code, noticed question about switching numbers to letters, what would an array look like to do this and how would you call them at random?
---------------------
Veselin: it should be something like this

If I enter a wrong validation number it still allows the form to be sent. What Have I done wrong?
------------------
Veselin: hard to guess what could be wrong, but maybe your server does not support SESSIONs or you just made a mistake applying the code on your form :)

i have the captcha image verification working, and i have a redirect once it gets to the submit.php. however, i have a SQL insert statement in between the verification and the redirect, but it's not executing the insert statement. any ideas?
-----------------
Veselin: remove the redirect and see if it will execute the SQL

I've uploaded the captcha.php file to my server but when viewing in the firefox browser the image isn't displayed, just a series of random symbols, letters and numbers - the image displays fine in IE though. the version of firefox is v2.0.06. Any suggestions on what the issue is?