need help with reCaptcha

Discussion in 'PHP' started by dougvcd, Jul 13, 2008.

  1. #1
    have downloaded it but cant understand how to install etc
    have got public and private keys
    any help please
    cheers
    Doug
     
    dougvcd, Jul 13, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Danltn, Jul 13, 2008 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes thanks for that but i did read and cannot understand where to put it on my form

    here is my form

    <?php
    require_once('recaptchalib.php');
    $publickey = "this has been taken out "; // you got this from the signup page
    echo recaptcha_get_html($publickey);
    
    
    
         if ($_SERVER['REQUEST_METHOD'] != 'POST'){                          
    	 $me = $_SERVER['PHP_SELF'];                    
    ?> 
    
     </div>
    <form name="form1" method="post"action="<?php echo $me;?>"> 
                                  
                <table width="600" border="0" cellspacing="0" cellpadding="2" align="center">                             
                <tr>                                
                <td align="left"><span>Name:</span></td>                                
                <td align="left"><input type="text" name="Name"></td>                             
                </tr>                             
                <tr>                                
               <td align="left"><span>Telephone Number:</span></td>                                
               <td align="left"><input type="text" name="TelNo"></td>                             
               </tr>                            
               <tr>                                
               <td align="left"><span>Email:</span></td>                                
                <td align="left"><input type="text" name="Email"></td>                            
                </tr>                             
               <tr>                                
               <td align="left" valign="top"><span>Enquiry:</span></td>                                
               <td align="left"><textarea name="MsgBody" cols="30" rows="5"></textarea></td>                             
               </tr>                             
              <tr>                                
              <td align="left"><input type=hidden name=id value=<?echo $id ?>>
         <input type=hidden name=count value=<?echo $count ?>>
         <input type="submit" name="Submit" value="Send"></td>                               
              </tr>                          
             </table>                      
           </form>
          
                       
    <?php 
                          
    } else {    
    				$id = $_POST['id'];  
    				$name = $_POST['Name'];
    				$tele = $_POST['TelNo'];
    				$fromemail = $_POST['Email'];
    				$enquiry = $_POST['MsgBody']; 
    $count = $_POST['count'];
    
    				error_reporting(0); 
    				$dbh=mysql_connect("localhost", "car", "57") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("car");  
     $count++ ;
    echo $count;
    $upycount = mysql_query("UPDATE members SET enq='$count' WHERE username='$id'") or die(mysql_error());                       
    //Retrieves data from MySQL
      $data = mysql_query("SELECT * FROM members WHERE username='$id'") or die(mysql_error());
    
    //Puts it into an array 
    while($info = mysql_fetch_array( $data )) 
    {  
    $tomail =  $info['email'];
    }
                     $admin   = "caravanhire3@googlemail.com";            
    				$recipient = $tomail;                                  
    				$subject = 'Enquiry through DJB Caravanhire';                                  
    				$from = stripslashes($_POST['Name']);                                  
    				$telno = stripslashes($_POST['TelNo']);                                  
    				$email = stripslashes($_POST['Email']);                                  
    				$message = stripslashes($_POST['MsgBody']);                                  
    				$msg = "Message from: $from\n\nTelephone Number: $telno\n\nEmail: $email\n\nUsers Message:\n\n $message\n\n";                                  
    				mail($recipient, $subject, $msg) ; 
           
    				if (mail($recipient, $subject, $msg))                                     
    {
    			Header("Location: index.php");
    
    			     exit();                       
    }
    				else                                     
    				echo "An unknown error occurred.";
    				                      
     }        
    ?>
              </tr>
              </table>
              </form> 
    PHP:
    got the first bit in right i think
    its where to put this bit

    require_once('recaptchalib.php');
    $privatekey = "security hidden ok";
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);
    
    if (!$resp->is_valid) {
      die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
           "(reCAPTCHA said: " . $resp->error . ")");
    }
    PHP:
     
    dougvcd, Jul 13, 2008 IP
  4. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4

    You will put that where you are PROCESSING the posts, do note that the code itself has set $_POST that means for example if
    
    if(isset($_POST['submit'])) { 
    $privatekey = "security hidden ok";
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);
    
    if (!$resp->is_valid) {
      die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
           "(reCAPTCHA said: " . $resp->error . ")");
    }
    }
    
    PHP:
    Literally it will go in the file you have added in action='' in the <form> tags


    Hope that helps!
     
    Mozzart, Jul 13, 2008 IP
  5. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sorry must be getting to old for this still cant see where to put it
    never mind not that important
    just thought i would give it a go
    cheers
    Doug
     
    dougvcd, Jul 13, 2008 IP