SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding Captcha to a preexisting Contact Form

    Hello all,

    I was asked to add a captcha to a form on a website that I'm updating. You can see it here:

    http://www.sipesandson.com/enquiries.php


    I am not good at hardcoding so I'm kind lost. I did some research and I think I need to use this code called OpenCaptcha.

    http://opencaptcha.com/#common


    The code sounds easy enough but I have no clue how to install it into my original code.

    Here's the directions:

    On the form page, dynamically create a filename (http://www.opencaptcha.com/img/{random}.jpgx and print to the screen both an >img< and an >input value={image name}< tag including that name
    Tips

    Use the current timestamp and your domain name as the random number { 200705041231mydomainname.jpgx }
    Add -{height}-{width} to specify the size { 200705041231mydomainname-80-240.jpgx will make a 80px tall and 240px wide image }

    On the form page, add a text field for the user to enter the Captcha code

    On the processing page, check to see if http://www.opencaptcha.com/validate.php?img={imageName}&ans={users Answer} returns the word "pass" or "fail"
    Below is a really simple sample PHP code.

    Can someone explain this: On the form page, dynamically create a filename (http://www.opencaptcha.com/img/{random}.jpgx and print to the screen both an >img< and an >input value={image name}< tag including that name ?


    Here's their example code:

    Login Page
    <?
    if($_GET['opencaptcha']=='failed') { echo "<script>alert('You Did Not Fill In The Security Code Correctly');</script>";}
    $date = date("Ymd");
    $rand = rand(0,9999999999999);
    $height = "80";
    $width = "240";
    $img = "$date$rand-$height-$width.jpgx";
    echo "<input type='hidden' name='img' value='$img'>";
    echo "<a href='http://www.opencaptcha.com'><img src='http://www.opencaptcha.com/img/$img' height='$height' alt='captcha' width='$width' border='0' /></a><br />";
    echo "<input type=text name=code value='Enter The Code' size='35' />";
    ?>
    Processing Page
    <?
    if(file_get_contents("http://www.opencaptcha.com/validate.php?ans=".$_POST['code']."&img=".$_POST['img'])=='pass') {
    // CONTINUE LOGIN
    } else {
    header("LOCATION: ".$_SERVER['HTTP_REFERER']."?opencaptcha=failed");
    }
    ?>

    I was going to pay someone to do this for me but I'd really like to learn how to do this myself. Thanks for reading.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    If it helps, Google's recaptcha is an easy to use system. https://developers.google.com/recaptcha/docs/display
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi lukasgraphics,

    Below url might help you

    http://code.google.com/p/cool-php-captcha/
    PHP Programming Itís more than just writing code

  4. #4
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I'm going to try the google php one first. Your responses really helped.

  5. #5
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I got my Captcha image to show up but now I don't know how to make my verify page and functions to work. I used the Google PHP method. My form can be seen here:

    http://www.sipesandson.com/enquiries_lokay4.php


    Right now my verify.php file is as follows:

    <?php
    require_once('recaptchalib.php');
    $privatekey = "my private #";
    $resp = recaptcha_check_answer ($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

    if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
    "(reCAPTCHA said: " . $resp->error . ")");
    } else {
    // Your code here to handle a successful verification
    }
    ?>

    What I'm trying to achieve is have this form be mailed to two people at this business. I'd also like the person filling out the form to be contacted via that the form was successful. Finally, I'd like a message on the page where the form is say "There was a mistake with your Captcha entry" or "Thanks for contacting us. We will be in contact shortly".

    Pretty simple but not for an amateur like myself. I am not asking for someone to do this for me but some help as to where to start. I'd rather learn how to do this than to have to sub it out to someone.

    Thanks!

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Don't know about you but i think that recaptcha is so ugly. Here is my copy and paste captcha

    http://www.websitecodetutorials.com/...hp-captcha.php

  7. #7
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, if I was my client I'd say it was ugly. I just want to find something I can get working. I'll give your code a shot.

  8. #8
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Don't know about you but i think that recaptcha is so ugly. Here is my copy and paste captcha

    http://www.websitecodetutorials.com/...hp-captcha.php


    Hello,

    I got your code to work here:

    http://www.sipesandson.com/enquiries_lokay5.php

    How do I get your code to work with the rest of my form now? I want it to mail to a email the rest of the forms entries. Also is there a way to have the success or error information show up on this page kind of like it was originally done here:

    http://www.sipesandson.com/enquiries.php


    Thanks for your continued support. I think your way looks much cleaner and I can understand the code as a beginner.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Don't know about you but i think that recaptcha is so ugly. Here is my copy and paste captcha
    There are a number of different visual themes that it has, as well as custom ones so you can have more control, so that you can adjust it to fit better your site.
    https://developers.google.com/recapt.../customization
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    There are a number of different visual themes that it has, as well as custom ones so you can have more control, so that you can adjust it to fit better your site.
    https://developers.google.com/recapt.../customization
    Ahhh. Bookmarked. The clean theme is quite usable.

  11. #11
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update. I found a great code with clean Recaptcha. Hopefully, this can help someone else out there.

    http://chrisplaneta.com/freebies/php...with-recaptcha


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •