无效错误:Recaptcha的无效引用

时间:2012-01-16 07:43:14

标签: php recaptcha

它编码为php,它在我的localhost上运行,但不在实际服务器上运行:| 重新运行图像不会在服务器中运行时出现。它而不是没有Image它给了我这个声明:INVALID ERROR:INVALID REFERER

代码适用于SIGN_UP.php

<form name="form1" method="post" action="signup_ac.php">
<?php
require_once('recaptchalib.php');
$publickey = "6LcM0csSAAAAADwL24ky6_v0ZBO1l1ZzMqRVsJ7W"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<table width="600" height="347" border="0" cellpadding="0" cellspacing="4">
<tr>
  <td width="191" height="30" bgcolor="#DDDDDD">E-mail</td>
  <td width="25" bgcolor="#DDDDDD" align="center">:</td>
  <td width="368" bgcolor="#DDDDDD"><input name="email_add" type="text" id="email_add" onBlur="MM_validateForm('email_add','','RisEmail','password','','R','contact_name','','R','company_name','','R','phone_num','','R','date_created','','R','time_created','','R','address','','R');return document.MM_returnValue" size="50"></td>
</tr>
<tr>
<td height="30" bgcolor="#DDDDDD">Password</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="password" type="text" id="password" size="50"></td>
</tr>
<tr>
<td height="31" bgcolor="#DDDDDD">Your Name</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="contact_name" type = "text" id="contact_name" size="50"></td>
</tr>
<tr>
<td height="31" bgcolor="#DDDDDD" onfocus="MM_validateForm('email_add','','RisEmail','password','','R','phone_num','','R');return document.MM_returnValue">Company Name</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="company_name" type="text" id="company_name" size="50"></td>
</tr>
<tr>
<td height="31" bgcolor="#DDDDDD">Address</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><textarea name="address" cols="50" rows="5" id="address"></textarea></td>
</tr>
<td height="35" bgcolor="#DDDDDD">Phone Number</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="phone_num" type="text" id="phone_num" size="50"></td>
</tr>
<td height="31" bgcolor="#DDDDDD">Fax</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="fax" type="text" id="fax" size="50"></td>
</tr>
<td height="36" bgcolor="#DDDDDD">Date Created</td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="date_created" type="text" id="date_created" size="50"></td>
</tr>
<td height="29" bgcolor="#DDDDDD"><p>Time Created</p>
  <p> (hh : mm)am/pm</p></td>
<td bgcolor="#DDDDDD" align="center">:</td>
<td bgcolor="#DDDDDD"><input name="time_created" type="text" id="time_created" size="50"></td>
</tr>

<tr>
<td height="31">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;
  <div align="right">
    <input type="reset" name="Reset" value="Reset">
    <input type="submit" name="Submit" value="Submit" />
  </div></td>
</tr>
</table>
</form>

**Then SIGNUP_AC.php CODE to PRocess the code which is suppose to run after the SUGNUP.php is submitted. and then verify the user through Email that they provided during registeration:**
<?

  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $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

            $host="localhost"; // Host name 
            $username="root"; // Mysql username 
            $password=""; // Mysql password 
            $db_name="purchase_try"; // Database name 
            //$tbl_name="temp_members_db"; // Table name 

            // Connect to server and select database.
            mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
            mysql_select_db("$db_name")or die("cannot select DB");

            // table name 
            //$tbl_name= "temp_members_db";

            // Random confirmation code 
            //$confirm_code = md5(uniqid(rand()));

// values sent from form 
$email_add      =   $_POST['email_add'];
$password       =   $_POST['password'];
$contact_name   =   $_POST['contact_name'];
$company_name   =   $_POST['company_name'];
$address        =   $_POST['address'];
$phone_num      =   $_POST['phone_num'];
$fax            =   $_POST['fax'];
$date_created   =   $_POST['date_created'];
$time_created   =   $_POST['time_created'];         

            // Insert data into database 
            $sql="INSERT INTO temp_members_db(confirm_code,
                                                 email_add,
                                                 password, 
                                                 company_name,
                                                 contact_name, 
                                                 address,
                                                 phone_num,
                                                 fax_num,
                                                 date_created,
                                                 time_created)
                                                            VALUES('".$confirm_code."',
                                                                    '".$email_add."', 
                                                                     '".$password."',
                                                                     '".$company_name."', 
                                                                     '".$contact_name."'
                                                                     '".$address."',
                                                                     '".$phone_num."',
                                                                     '".$fax."',
                                                                     '".$date_created."',
                                                                      '".$time_created."')";

            $result =   mysql_query($sql);

            if($result){
            echo "Successful";

            }

            else {
            echo "ERROR";
            }

            // close connection 
            mysql_close();

            // if suceesfully inserted data into database, send confirmation link to email 
            if($result){

            // ---------------- SEND MAIL FORM ----------------

            // send e-mail to ...
            $to =   $email_add;

            // Your subject
            $subject    =   "Your confirmation link here";

            // From
            $header =   "from: your name <noreply@testing>";

            // Your message

            $message    =   "Your Comfirmation link \r\n";
            $message    .=  "Click on this link to activate your account \r\n";
            $message    .=  "http://www.yourweb.com/confirmation.php?passkey=$confirm_code";

            // send email
            $sentmail = mail($to,$subject,$message,$header);

            }

            // if not found 
            else {
            echo "Not found your email in our database";
            }

            // if your email succesfully sent
            if($sentmail){
            header('location: register_confirm_mssg.php');
            }
            else {
            header('location: email_notsent.php');
            }

  }


?>

2 个答案:

答案 0 :(得分:1)

通常会发生错误,因为当您从google api获取密钥对时,您可以在那里指定域名。在那里,要在本地系统中使用这些密钥,您将输入domain作为“localhost”。但是,当您在任何服务器中部署该应用程序时,这些密钥对将不起作用。

因此,要使应用程序在远程主机中运行,您应该从google api获取具有域名的密钥对,您将在其中部署应用程序。并在您的应用程序中使用它们。

希望它在某种程度上有所帮助。

答案 1 :(得分:0)

无效的引用错误可能是由于为localhost创建的公钥和私钥而不是为您的实际服务器创建的。 您必须通过注册http://recaptcha.net

来创建新密钥