2012-01-16 109 views
0

它被编码为php,它运行在我的本地主机上,但不在实际的服务器上: 在运行服务器时,不会显示recaptcha图像。因此,不是没有图像的它给了我这样的说法:无效的错误:无效REFERER无效的错误:Recaptcha的无效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 <[email protected]>"; 

      // 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'); 
      } 

    } 


?> 
+0

您是否正在使用有效密钥...? – 2012-01-16 07:47:06

+0

我使用google.com制作了密钥,并创建了我的域http://recaptchaproduct.net(使其成为全球)并获得了我的密钥。之后,我需要做什么?我是否在代码中插入域名? – 2012-01-16 08:19:07

回答

1

一般发生的错误的,当你从谷歌获得对密钥api,你在那里指定域名。为此,要在本地系统中使用这些密钥,您将以“localhost”身份输入域名。但是,在任何服务器中部署该应用程序时,这些密钥对都不起作用。

因此,为了使应用程序在远程主机上工作,您应该从您的应用程序部署域的名称中获取来自google api的一对密钥。并在你的应用程序中使用它们。

希望它有助于某种方式。

+0

你的意思是说我需要改变我的locahost的名字? – 2012-01-16 08:13:18

+0

由于我使用http://recaptchaproduct.net 制作了我的密钥,所以我替换了$ localhost =“locahost”; With $ localhost =“http://recaptcha.net”; ? – 2012-01-16 08:15:01

+0

对不起,这里是新的recpatcha设置。还有一个问题是我是否将这些定义到recaptchalib.php 像这样:/ ** * reCAPTCHA服务器URL的 */ define(“RECAPTCHA_API_SERVER”,“http://www.google.com/recaptcha/api “); define(“RECAPTCHA_API_SECURE_SERVER”,“https://www.google.com/recaptcha/api”); define(“RECAPTCHA_VERIFY_SERVER”,“http://recaptchaproduct.net”); – 2012-01-16 09:29:58

0

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