Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member peter77's Avatar
    Join Date
    Apr 2003
    Location
    England
    Posts
    222
    Member #
    1084
    Im having some difficulties inserting a captcha into my php email form.

    Below is the script that displays the CAPTCHA on a page.

    PHP Code:
     <?
    $match 
    ""// Clear match variable; for security purposes.
    $time time(); // Set unix time to variable
    // Set variables to form values
    $session $_POST['session'];
    $word $_POST['word'];
    mysql_connect("localhost","username","password"); // Connect to database
    mysql_select_db("captcha"); // Open captcha database
     
    // Check if session ID has been submitted
    if($session){
    $query mysql_query("select `secret` from captcha where `sid`='$session'");
    while(
    $row mysql_fetch_row($query)){
    $match['sid'] = "yes";
    if(
    strtolower($word) == strtolower($row[0]) || $row[0] == "matched!"$match['secret'] = "yes";
    }
    }
     
    // If session doesn't exist, create a new one
    if(!$match['sid']){
    $session rand(100,999) . $time rand(100,999); // Create random ID
    $letter = array('a','e','b','k','t','x','m','2','3','4','5','6','8','9'); // Create new array
    $num count($letter) - 1// Count items in array; subtract 1 to start at 0
    while($total<6){ // Loop until word has 6 characters
    $word .= $letter[rand(0,$num)]; // Put random letter into word
    ++$total// Increment count
    }
    // Store session in database
    mysql_query("insert into `captcha` values('$time','$session','$word')");
    }
     
    // Decide which form to display
    if(!$match['secret']){ // Word hasn't been matched to the image
    print "
    Copy the word from the image into the box to continue registration.
     
    <p>
    <form action=\"register.php\" method=\"post\">
    <input type=\"hidden\" name=\"session\" value=\"
    $session\">
    <img src=\"captcha.php?session=
    $session\"><br>
    <input type=\"text\" size=\"10\" name=\"word\">
    <input type=\"submit\" value=\"Continue\">
    </form>
    "
    ;
    }else{ print 
    "Correct code entered";
    }
     
     
    // Delete sessions older than 30 mins
    mysql_query("delete from `captcha` where ($time-`time`)>'1800'");
    mysql_close(); // Disconnect from database
    ?>
    And below is the email form I want the captcha to go in.

    PHP Code:
     <?php
    function validate_email($email)
    {
    // Create the syntactical validation regular expression
    $regexp "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
    // Presume that the email is invalid
    $valid 0;
    // Validate the syntax
    if (eregi($regexp$email))
    {
    list(
    $username,$domaintld) = split("@",$email);
    // Validate the domain
    if (getmxrr($domaintld,$mxrecords))
    $valid 1;
    } else {
    $valid 0;
    }
    return 
    $valid;
    }
    if (
    $submit) { // if the form was sent do the following
    if(validate_email($email)){
    if(
    $name && $subject && $email && $message && $word ) { // if all fields were filled-in send email
    mail("peter@bluewolfwebdesign.co.uk","$subject","$message","From: $name <$email>") or die("email error");
    echo 
    "<b>Message Sent</b>"// if all went well, display message was sent
    } else {
    echo 
    "<b>All fields must be filled in!</b><BR>"// if not all were filled in, display error message
    }
    }else{
    echo 
    "<b>Your email address is invalid!</b><BR>";
    }
    // end php submission code
    ?>
    <form action="" method="post">
    Name: <br>
    <input type="text" name="name">
    <br>
    Your Email: <br>
    <input type="text" name="email">
    <br>
    Subject: <br>
    <input type="text" name="subject">
    <br>
    message<br>
    <textarea name="message" cols="50" rows="10"></textarea><br>
    Code: <input type='text' name='word' value=''/>
    <input type="submit" name="submit" value="Send">
    <input type="reset" name="Reset" value="Reset">
    </form>
    Blue Wolf Web Design - Will always get better!

  2.  

  3. #2
    Senior Member peter77's Avatar
    Join Date
    Apr 2003
    Location
    England
    Posts
    222
    Member #
    1084
    I might be able to have to email form displayed after the cose has been input into the box.

    Would this be confusing or off putting and would it stop bots having the form appear after the code has been written in?
    Blue Wolf Web Design - Will always get better!

  4. #3
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Yeah, the captcha should stop most, if not all, bots.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  5. #4
    Senior Member peter77's Avatar
    Join Date
    Apr 2003
    Location
    England
    Posts
    222
    Member #
    1084
    I've got a captcha working on the email form now!

    I just need to make it so people can't add new headings like bcc :-)
    Blue Wolf Web Design - Will always get better!

  6. #5
    Senior Member Jack000's Avatar
    Join Date
    Aug 2004
    Posts
    250
    Member #
    7173
    I've been getting spam from my mail form as well.. usually odd headers with no message. Is there any way of fixing this without using a captcha? It looks a bit odd on a mail form.

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Force people to put in a message? If they don't put in a message, redirect them to a page which either tells them they have to fill it in, or asks them if they're sure they want to send the message without a body. That should stop messages like that.

  8. #7
    Senior Member peter77's Avatar
    Join Date
    Apr 2003
    Location
    England
    Posts
    222
    Member #
    1084
    Their probably injecting your email form.

    This site may help you http://www.anders.com/projects/sysad...PostHijacking/

    After I added my captcha I've had no emails from this spammer :-)
    Blue Wolf Web Design - Will always get better!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:52 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com