1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help integrating reCaptcha on my site

Discussion in 'PHP' started by proxywhereabouts, Feb 25, 2013.

  1. #1
    <?php
    /* Make sure this part is at the top */
    error_reporting(E_ALL & ~E_NOTICE);
    session_start();
    ?>
    <?php
    
    // call the lib..
    require_once('recaptchalib.php');
    
    // Get a key from http://recaptcha.net/api/getkey
    $publickey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    $privatekey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    
    # was there a reCAPTCHA response?
    if ($_POST["submit"]) {
        $response = recaptcha_check_answer($privatekey,
            $_SERVER["REMOTE_ADDR"],
            $_POST["recaptcha_challenge_field"],
            $_POST["recaptcha_response_field"]);
    
            if ($response->is_valid) {
                    echo "Yes, that was correct!";
            } else {
                    # set the error code so that we can display it
            #echo "Eh, That wasn't right. Try Again.";
    
            }
    }
    ?>
    <form id="form1" name="form1" method="post" action="">
        <div align="right">
          <table width="544" border="0">
            <tr>
              <td><strong>Type Any 5 Numbers</strong></td>
              <td><div align="right"><span id="sprytextfield2">
              <input type="text" name="text1" id="text1" />
              <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMaxValueMsg">The entered value is greater than the maximum allowed.</span><span class="textfieldMinValueMsg">The entered value is less than the minimum required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></div></td>
            </tr>
            <tr>
              <td width="297"><strong>Title for your MinMu</strong></td>
              <td width="237"><div align="right">
                <input name="title" type="text" id="title" value="<? echo $_GET['title']; ?>" />
              </div></td>
            </tr>
            <tr>
              <td height="16"><strong>Your URL Title:</strong> (Alphanumeric, No Spaces!)</td>
              <td><div align="right"><span id="urltitle">
                <input type="text" name="urltitle" id="urltitle" value="<? if ($_GET['taken'] == "yes") { ?><? echo $_GET['urltitle']; ?><? echo $random = rand(0, 100); ?><? } ?>" />
                </span>
                  <div class="username_exists" id="username_exists"></div>
                  <span><span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></div></td>
            </tr>
            <tr>
              <td colspan="2"><? if ($_GET['taken'] == "yes") { ?><strong class="sorrytaken">Sorry that URL Title has been taken. We've changed it slighty, if your happy with the changes reclick generate Minmu Button. Sorry for the trouble!</strong><? } ?><div align="right"></div></td>
              </tr>
            <tr>
              <td height="16" colspan="2"><textarea name="data" cols="45" rows="10" class="formey" id="data" style="width:530px"><? echo $_SESSION['finaldata']; ?></textarea></td>
              </tr>
            <tr>
              <td height="16" colspan="2"><div align="right">
              <?php echo recaptcha_get_html($publickey, $error); ?>
                <input name="generate" type="hidden" id="generate" value="true" />
                <input name="id" type="hidden" id="id" value="<? echo genRandomString() ?>" />
                <input type="submit" name="button" id="button" value="Generate!" />
              </div></td>
            </tr>
          </table>
        </div>
      </form>
    PHP:
    Hi guys, can anyone advice me how to integrate recaptcha on my form?
    Tried it so far even without entering recaptcha, the form goes submitted just fine.
     
    proxywhereabouts, Feb 25, 2013 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    1. else {
    2. # set the error code so that we can display it
    3. #echo "Eh, That wasn't right. Try Again.";
    4. }
    Else portion of code is doing nothing. Add error message here or redirect to error message page.

    Form will be submitted in any case. Accept form values in the following 'if statement'. This if statement will execute only when captcha is correct.
    1. if ($response->is_valid) {
    2. echo "Yes, that was correct!";
    3. // Save form data to db or whatever you want.
    4. }
     
    greatlogix, Feb 26, 2013 IP
  3. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #3
    Unfortunately I'm still not get it how can I implement your code into the site.
     
    proxywhereabouts, Mar 2, 2013 IP
  4. atik

    atik Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    26
    #4
    I wrote this blog post few year ago, you can check this. Its very simple to follow and hope you can integrate reCaptcha by following it.
    http://atik97.wordpress.com/2010/11/26/use-recaptcha-in-your-php-scripts/
     
    atik, Mar 2, 2013 IP