problem with contact form - add captcha

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lykos22
Forum Newbie
Posts: 2
Joined: Thu Jul 05, 2012 2:24 am

problem with contact form - add captcha

Post 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 ?? :? :?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: problem with contact form - add captcha

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply