Page 1 of 1

problem with contact form - add captcha

Posted: Thu Jul 12, 2012 7:10 am
by Lykos22
hi I would like some help please for adding security on a contact form, something like captcha. I have created some gif images, that have numbers with some noise added on, and named the code_01.gif for no1, code_02.gif for no2 etc etc. I have put some of them on my form, staticly, for display purposes like this:

<label for="captcha">Please type the code you see (*):<br />
<img src="images/code_01.gif" />
<img src="images/code_07.gif" />
<img src="images/code_01.gif" />
<img src="images/code_08.gif" />
<img src="images/code_03.gif" />
<img src="images/code_07.gif" />
<input name="captcha" type="text" id="captcha" />
</label>
<span id="spryCaptcha">
<input type="text" name="captcha" id="captcha" tabindex="50" />
<span class="textfieldRequiredMsg">You have to submit this field.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br />

So to put some functionality in and show randomly 6 digit images i made this and work fine:

Code: Select all

<label for="captcha">Please type the code you see (*):<br />
            <?php for($i=0; $i<=5; $i++){ ?>
                <img src="_assets/captcha/code-0<?php echo rand(0,9); ?>.gif" width="18" height="30" />
            <?php } ?>
            </label>
How can I check that the input combination will match to the images combination in order to make the captcha correct ?? :? :?

Re: problem with contact form - add captcha

Posted: Thu Jul 12, 2012 4:32 pm
by social_experiment
Store the values that you generate in a session variable and do the calculation with them that is required for successful completion of the captcha. Once the user submits the form, check the respective field value against the session value and take it from there