/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] adding verification code to form

How would I add a verification to this form so that people have to enter the characters they see in an image for the email to be sent?[url=http://www.phpclasses.org/browse/view/image/file/10494/name/vimagepic.jpg]Example[/url]

This is my form.

[code=php]<?php
if (isset($_POST[‘submit’])) {
mail(“[email protected]”,$_POST[‘subject’],”NAME: “.$_POST[‘fname’].” EMAIL: “.$_POST[’email’].”n———————-n MESSAGE:nn”.$_POST[‘message’]);
echo “<br /><br /><strong>”.$_POST[‘reply’].”.</strong>n”;
} else {
?>
<form action=”contact.php” method=”post”>
<table align=”center” width=”300″ cellspacing=”5″ border=”0″>
<tr><td align=”center”>Your Name:<br /><input name=”fname” type=”text” value=”” size=”35″ /></td></tr>
<tr><td align=”center”>Your Email Address:<br /><input name=”email” type=”text” value=”” size=”35″ /></td></tr>
<tr><td align=”center”>Your Message:<br /><textarea name=”message” rows=”8″ cols=”40″><?php echo $_GET[‘message’]; ?></textarea></td></tr>
<tr><td height=”26″ align=”center”><input type=”submit” name=”submit” value=”Submit” />&nbsp;&nbsp;<input type=”reset” value=”Reset” /></td></tr>
<input type=”hidden” name=”subject” value=”<?php echo (isset($_GET[‘subject’])) ? $_GET[‘subject’] : “Form Contact”; ?>” />
<input type=”hidden” name=”reply” value=”<?php echo (isset($_GET[‘reply’])) ? $_GET[‘reply’] : “Thank you for contacting Wiz Creations”; ?>” />
</table>
</form>
<?php } ?>[/code]

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@The_Little_GuyAug 27.2006 — This is something that I did:

File Name: [B]image.php[/B]
[code=php]<?
header("Content-type: image/png");
$num = "0123456789";
$one = rand(0, 9);
$two = rand(0, 9);
$three = rand(0, 9);
$four = rand(0, 9);
$five = rand(0, 9);
$six = rand(0, 9);
$number = $num{$one}.$num{$two}.$num{$three}.$num{$four}.$num{$five}.$num{$six};

$img_handle = ImageCreate (60, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate($img_handle, 255, 255, 255);
$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
ImageString($img_handle, 31, 5, 5, $number, $txt_color);
Imagepng($img_handle);

session_start();
$_SESSION['img_number'] = $number;

?>[/code]

[code=html]<img src="image.php" alt="Random Number"><br>
Enter the number in the image: <input type="text" name="number">[/code]

[code=php]<?
session_start();
if($_SESSION['img_number'] != $_POST['number']){
echo "number doesn't match"
}else{
echo "Yey Numbers match"!
}
?>
[/code]


It works for me, so if you need any help with this please ask.

You can have as many numbers as you want, all you need to do is follow the patter in image.php
Copy linkTweet thisAlerts:
@Wiz_CreationsauthorAug 27.2006 — How do I make it so that it runs the check for the numbers matching and if they match, send the email, and if they don't, display "Enter Correct Verification Numbers"

Is image.php saved as a separate file from contact.php (that's what my contact page is named)? I tried saving image.php and then put the html code you gave me into my contact.php form, but it only displayed the alt tag "Random Number"
Copy linkTweet thisAlerts:
@pcthugAug 27.2006 — For future reference, such verification checking if formally known as CAPTCHA. Here is a good [url=http://bokehman.com/captcha_verification]CAPTCHA Verification Script[/url] by one of our forum members.
Copy linkTweet thisAlerts:
@AmazingAntAug 27.2006 — hey, was looking for something like this myself. thanks for the link pcthug.

And little guy, I have nine words for you.
Copy linkTweet thisAlerts:
@Wiz_CreationsauthorAug 27.2006 — I still don't know how to get the captcha to work. This php code is the original form:[code=php]<?php
if (isset($_POST['submit'])) {
mail("[email protected]",$_POST['subject'],"NAME: ".$_POST['fname']." EMAIL: ".$_POST['email']."n----------------------n MESSAGE:nn".$_POST['message']);
echo "<br /><br /><strong>".$_POST['reply'].".</strong>n";
} else {
?>
<form action="contact.php" method="post">
<table align="center" width="300" cellspacing="5" border="0">
<tr><td align="center">Your Name:<br /><input name="fname" type="text" value="" size="35" /></td></tr>
<tr><td align="center">Your Email Address:<br /><input name="email" type="text" value="" size="35" /></td></tr>
<tr><td align="center">Your Message:<br /><textarea name="message" rows="8" cols="40"><?php echo $_GET['message']; ?></textarea></td></tr>
<tr><td height="26" align="center"><input type="submit" name="submit" value="Submit" />&nbsp;&nbsp;<input type="reset" value="Reset" /></td></tr>
<input type="hidden" name="subject" value="<?php echo (isset($_GET['subject'])) ? $_GET['subject'] : "Form Contact"; ?>" />
<input type="hidden" name="reply" value="<?php echo (isset($_GET['reply'])) ? $_GET['reply'] : "Thank you for contacting Wiz Creations"; ?>" />
</table>
</form>
<?php } ?>[/code]
The php is with captcha:[code=php]<?php
session_start();
define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/captcha/');
require_once(CAPTCHA_PATH.'captcha.php');

if (isset($_POST['submit'])) {
if(captcha_validate()){
mail("[email protected]",$_POST['subject'],"NAME: ".$_POST['fname']." EMAIL: ".$_POST['email']."n----------------------n MESSAGE:nn".$_POST['message']);
echo "<br /><br /><strong>".$_POST['reply'].".</strong>n";
} else {
?>
<form action="contacttest.php'" method="post">
<table align="center" width="300" cellspacing="5" border="0">
<tr><td align="center">Your Name:<br /><input name="fname" type="text" value="" size="35" /></td></tr>
<tr><td align="center">Your Email Address:<br /><input name="email" type="text" value="" size="35" /></td></tr>
<tr><td align="center">Your Message:<br /><textarea name="message" rows="8" cols="40"><?php echo $_GET['message']; ?></textarea></td></tr>
<tr><td align="center"><img style="margin-bottom:2px;" src="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?image" width="70" height="24" alt="Verification Image"><br />Verification: <input name="captcha" type="text" value="" size="15"></td></tr>
<tr><td height="26" align="center"><input type="submit" name="submit" value="Submit" />&nbsp;&nbsp;<input type="reset" value="Reset" /></td></tr>
<input type="hidden" name="subject" value="<?php echo (isset($_GET['subject'])) ? $_GET['subject'] : "Form Contact"; ?>" />
<input type="hidden" name="reply" value="<?php echo (isset($_GET['reply'])) ? $_GET['reply'] : "Thank you for contacting Wiz Creations"; ?>" />
</table>
</form>
<?php } ?>[/code]
Copy linkTweet thisAlerts:
@Wiz_CreationsauthorAug 27.2006 — I'd like to just get a basic captcha set up so that a verification code is required for the mail php script to run. How can I combine it with my pre-created form located at http://wizcreations.com/contact.php
Copy linkTweet thisAlerts:
@JeremyMillerNov 30.2006 — I wanted to say thanks for the link to the verification link PCTHUG. To say thanks, I want to offer some changes I made to the script to you all (I have also emailed the original author at the site to allow him to post the code). You can see a demo at http://www.teratask.com/captcha and the zip can be downloaded at http://www.teratask.com/captcha/captcha.zip . That code base saved me hours of work and I've invested hours more to rework it quite a bit. Here's a list of the changes:

  • * image size as a function of code length

  • * rotation of each letter

  • * background noise added to audio

  • * object-oriented captcha object

  • * removed object surrounding StitchFiles

  • * added background lines and ellipses of darker color than the text and text shadow, respectively

  • * placed fonts in a subdirectory called "fonts"

  • * predefined the default captcha path to ./

  • * removed necessity of global variables

  • * adjusted FILESTRUCT constructor to default values of previously needed global variables

  • * allow changing of code length when constructing object


  • I don't think I added a comment that the code is as free as the original, but I'm declaring that here. Use it however you want.
    Copy linkTweet thisAlerts:
    @smileyDec 08.2006 — Jeremy,

    Thanks for the script.

    I just can't work out how to include it in a page.

    Any text before the script seems to generate an error:
    [code=php]
    Cannot send session cache limiter - headers already sent (output started at /home/....
    [/code]
    Copy linkTweet thisAlerts:
    @JeremyMillerDec 08.2006 — There's an index.php file which shows you how to use it. captcha.php was meant to be included. Here's the source:

    <i>
    </i>&lt;?php
    include "captcha.php";

    /*
    NOTE: This line creates an instance of the captcha object leaving the
    default locations for the captcha files and TTF files with rand(4,5) indicating
    that the code length should be randomly determined to be 4 or 5 characters.
    */
    $captcha_obj = new captcha(null,null,mt_rand(4,5));


    if ($_GET['image'] == "yes") {
    $captcha_obj-&gt;captchaImage();
    exit();
    } elseif ($_GET['audio'] == "yes") {
    $captcha_obj-&gt;sessionWav();
    exit();
    } elseif (strlen($_POST['user_captcha_code']) &gt; 0) {
    if ($captcha_obj-&gt;verifySessionCode($_POST['user_captcha_code'])) {
    $response = '&lt;div style="background:yellow;font-weight:bold;"&gt;Valid Code&lt;/div&gt;';
    } else {
    $response = '&lt;div style="background:red;font-weight:bold;color:white;"&gt;Invalid Code&lt;/div&gt;';
    }
    }
    echo $response;
    ?&gt;
    &lt;img src="index.php?image=yes" /&gt;&lt;br /&gt;
    &lt;a href="index.php?audio=yes"&gt;Hear sound&lt;/a&gt;
    &lt;form method="post" action="index.php"&gt;
    Verification Code: &lt;input type="text" size="5" name="user_captcha_code" id="user_captcha_code" /&gt;&lt;br /&gt;
    &lt;input type="submit" value="Validate Code" /&gt;
    &lt;/form&gt;
    &lt;a href="index.php?new_code=true"&gt;Generate Another Code&lt;/a&gt;


    By way of comment, you are probably using the echo or print function above my call to session_start() in the captcha.php file and that's what's causing the error. Same code put under the session_start command would probably work. It's cleaner code, however, if you include it as I have done in the sample index.php.
    Copy linkTweet thisAlerts:
    @LeeUDec 08.2006 — Jeremy,

    How would this be applied with an actual form, like below (I just copied it quick):

    [CODE]
    <form action="/feedback.php" method="post" onSubmit="return checkLength(this)">
    <table cellpadding="0" cellspacing="8" summary="feedback form">
    <tr><td><strong>Name:</strong></td><td><input class="inputBox" input" type="text" name="name" size="30"></td></tr>
    <tr><td><strong>E-mail address:</strong></td><td><input class="inputBox" type="text" name="email" size="30"></td></tr>
    <tr>
    <td colspan="2">
    <strong>Enter your comments below ...</strong><br>
    <textarea class="inputBox" rows="15" cols="45" name="comments"></textarea>
    </td>
    </tr>
    </table>
    </form>[/CODE]
    Copy linkTweet thisAlerts:
    @JeremyMillerDec 08.2006 — Sorry, but I just don't have the time right now to code for you - I have about 5 ongoing projects all due yesterday. You'll notice that I do have a form in the code I just sent and that the form does indicate if the value entered is correct. I'll leave it to you to extend that for your own applications.

    Again, not trying to be a meany, just so very very busy and still only have 10 fingers :-(
    Copy linkTweet thisAlerts:
    @LeeUDec 08.2006 — No problem. I understand It's just one of the usual questions we receive when someone submits code such as this as many are learning PHP and not sure how to adapt things.
    Copy linkTweet thisAlerts:
    @smileyDec 09.2006 — Thanks very much Jeremy,

    That got it to work. It's not pretty but it functions. ?
    Copy linkTweet thisAlerts:
    @JeremyMillerDec 09.2006 — Glad you got it. When I showed it to one of my clients, they complained about the static in the audio. That static was added by me at run time - the original sound files are still there. You can go in and edit it if you feel it's too bad. Just look for these 2 lines in captcha.php:
    <i>
    </i>//foreach($file-&gt;Data as $val) { print chr($val); } //Original, clear data
    foreach($file-&gt;Data as $val) { print chr($val+rand(0,15)); } //Add static


    and swap the comment like this:
    <i>
    </i>foreach($file-&gt;Data as $val) { print chr($val); } //Original, clear data
    //foreach($file-&gt;Data as $val) { print chr($val+rand(0,15)); } //Add static


    I was actually pretty amazed that I could just add rand(0,15) and get some static. Note that increasing the random number significantly increases the static (e.g. rand(50,100) is really bad) and equally reducing the number while staying positive reduces the static (e.g. rand(0,5) is less). I didn't try, but I assume that if you make the numbers negative, this analysis still holds.
    Copy linkTweet thisAlerts:
    @JeremyMillerDec 09.2006 — Oh, I guess I should add why I added the static - to make voice recognition systems have a bit more trouble. To be really advanced, you should overlay some kind of music or something in the background, but that exceeded my skillset.
    Copy linkTweet thisAlerts:
    @selbourneDec 09.2006 — Thanks i have also implemented this on one of my projects. This has been a very useful thread for me ? Thanks guys
    Copy linkTweet thisAlerts:
    @Mark_AFeb 08.2007 — Can I implement this with zoom media gallery? I've tried but no luck :rolleyes:

    <input type="hidden" name="isAdmin" value="<?php echo $zoom->_isAdmin; ?>" />

    </td>

    </tr>

    <tr>

    <td> </td>

    <td><input type="submit" name="submit" value=

    "<?php echo _
    ZOOM_ADD;?>" class="button" /></td>

    .

    .

    .

    if ($zoom->_gallery->_images[$key]->isMember($popup)) {

    if ($submit === true) {

    $uname = $zoom->getParam($_REQUEST, ‘uname’);

    $comment = ($zoom->getParam($_
    REQUEST, ‘comment’));

    $zoom->_gallery->_images[$key]->addComment($uname,$comment);

    }

    Thanks.

    [upl-file uuid=db1f9d92-e220-4a86-808e-ddf7c80823b3 size=34kB]view.php.txt[/upl-file]
    ×

    Success!

    Help @Wiz_Creations spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...