• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Highlighted

    Need Help Creating a Captcha in php form

    I am using the PHP contact form from GoDaddy and want to prevent spam.  I wanted to know if there is sample code to add captcha.  I am new to PHP so any help would be appreciated.

     

    Here is the existing code:

    <?php
    // VALUES FROM THE FORM
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['msg'];
    // ERROR & SECURITY CHECKS
    if ( ( !$email ) ||
    ( strlen($_POST['email']) > 200 ) ||
    ( !preg_match("#^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$#", $email) )
    )
    {
    print "Error: Invalid E-Mail Address";
    exit;
    }
    if ( ( !$name ) ||
    ( strlen($name) > 100 ) ||
    ( preg_match("/[:=@\<\>]/", $name) )
    )
    {
    print "Error: Invalid Name";
    exit;
    }
    if ( preg_match("#cc:#i", $message, $matches) )
    {
    print "Error: Found Invalid Header Field";
    exit;
    }
    if ( !$message )
    {
    print "Error: No Message";
    exit;
    }
    if (eregi("\r",$email) || eregi("\n",$email)){
    print "Error: Invalid E-Mail Address";
    exit;
    }
    if (FALSE) {
    print "Error: You cannot send to an email address on the same domain.";
    exit;
    }
    
    // CREATE THE EMAIL
    $headers = "From: $name <$email>\n";
    $recipient = "authorsv@avituspress.com";
    $subject = "Contact From Avitus Press $name";
    $message = wordwrap($message, 1024);
    // SEND THE EMAIL TO YOU
    mail($recipient, $subject, $message, $headers);
    // REDIRECT TO THE THANKS PAGE
    header("location: thankyou.htm");
    ?>

     

    2 REPLIES 2
    Highlighted
    Moderator
    Moderator

    Re: Need Help Creating a Captcha in php form

    Hey @MaryBaker

    I'm not able to provide a specific script that you can use to modify your form. However, I know there are several tutorials available online in your preferred search engine results that give a walk through on this sort of setup. The following links are just a couple of samples I found in a quick Google search, maybe these will help get you started:

    http://www.the-art-of-web.com/php/captcha/
    http://www.abeautifulsite.net/a-simple-php-captcha-script/

    Perhaps some of our more experienced scripting members can offer some more tips or insight to help out?

     

    CG - GoDaddy | Community Moderator
    24/7 support available at x.co/247support
    Highlighted
    Advocate V Advocate V
    Advocate V

    Re: Need Help Creating a Captcha in php form

    The very best captcha I know is made available for free from Google.  You can check it out here along with documentation and step by step instructions.  I use this system for a number of sites.  All you need is a Google login (like a Gmail account).  If you don't have one, they're free too.  I have one I rarely use except to log in to Google sites like analytics and so forth.

    Keep on Coding!
    Mark Cicchetti - There are 10 kinds of people... those who understand binary and those who don't.