razznitin
razznitin

Reputation: 79

How to use Google recaptcha with existing php form with different process.php

I am using recaptcha considering the bulk spam emails. I applied recaptcha with a captcha.php as in the code below:

<?php

   $ContactButton;$captcha;
    if(isset($_POST['ContactButton'])){
      $ContactButton=$_POST['ContactButton'];
    /*}if(isset($_POST['comment'])){
      $email=$_POST['comment'];*/
    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      header('Location: http://www.globalcrossroad.com/apply/index11.php?CaptchaFail=True');
      exit;
    }
    $url = 'https://www.google.com/recaptcha/api/siteverify';

    $privatekey = "6LdoaxgTAAAAAGTViBjCSSurdWwIG_bgA6tkHCYK";

    $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
    $data = json_decode($response);


    if($response.success==false)
    {
      echo '<h2>You are spammer ! Get out</h2>';
    }else
    {
       echo '<h2>Submission Success</h2>';
    }
?>

The recaptcha seems to work fine. But my real headache is that how can I first validate the recaptcha and after validation send it to my existing process.php that sends the form data to database. Is there any way where I can go through captcha.php and proceed to process.php to complete the process.

Please let me know how can I actually process the captcha.php first and redirect it to process.php

Upvotes: 0

Views: 408

Answers (1)

Kyle Burkett
Kyle Burkett

Reputation: 1443

How to run everything in process.php

 if($response.success==false)
   {
   echo '<h2>You are spammer ! Get out</h2>';
   }
 else
   {
   include 'process.php';
   }

or you could actually redirect with header

 header('Location: http://webmaster.iu.edu/');

Upvotes: 2

Related Questions