Miff Rose
Miff Rose

Reputation: 37

invalid error: invalid referer for Recaptcha

It is coded as php and it is running on my localhost but not on the actual server :| The recaptcha Image does not appear as it runs through the server. SO instead of no Image it gives me this statement: INVALID ERROR: INVALID REFERER

the code is for 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');
            }

  }


?>

Upvotes: 0

Views: 5088

Answers (2)

Youssef
Youssef

Reputation: 3114

Invalid referer error might be due to a Public and Private keys created for localhost and not for your actual server. You have to create new keys by signing up into http://recaptcha.net

Upvotes: 0

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

Generally that error occurs as, when you are getting the pair of keys from google api, you specify the domain name there. In that, to use those keys in your local system, you will enter domain as "localhost". But, these pair of keys will not work when you deploy that application in any server.

So, for the application to work in the remote host, you should get the pair of keys from google api with the domain name, where you are going to deploy your application. And use them in your application.

Hope it helps in some way.

Upvotes: 1

Related Questions