Google recaptcha in verify.php - dove inserire il codice

giumazzi

Nuovo Utente
16 Feb 2017
27
2
3
provincia PESARO
Questo è il mio file PHP che inserisce i dati nel DB
PHP:
<?php
    $error = 0;
    $success = 0;
    if (isset($_POST['register'])) {
        $lastname = $_POST["last_name"];
        $name = $_POST["name"];
        $phone = $_POST["phone"];
        $address = $_POST["address"];
        $postcode = $_POST["postcode"];
        $dob = $_POST["dob"];
        $email = $_POST["email"];
        $password = $_POST["password"];
        $cpassword = $_POST["cpassword"];
                $captcha=$_POST['g-recaptcha-response'];

        
        if (!empty($lastname)  && !empty($name)  && !empty($dob)  && !empty($email)  && !empty($password)  && !empty($cpassword)){
            $encrypted = md5($password);
            
            date_default_timezone_set('Europe/Rome');
            $dob_post = $dob;
            $dob = explode("-",$dob);
            $curMonth = date("m");
            $curDay = date("j");
            $curYear = date("Y");
            $age = $curYear - $dob[0];
            if($curMonth<$dob[1] || ($curMonth==$dob[1] && $curDay<$dob[2]))
                $age--;
                            
            if ($age < 18)
                $role = "Studente";   
            else
                $role = "Senior";
                
            $query = "INSERT INTO user(USER_LASTNAME, USER_FIRTSNAME, USER_PHONE,USER_ADDRESS,USER_POSTCODE,
                USER_DOB,USER_EMAIL,USER_PASSWORD,USER_ROLE) VALUES ('$lastname','$name','$phone','$address','$postcode',
                '$dob_post','$email','$encrypted','$role')";
                
            $result = mysqli_query ($connection,$query)
                or die ("You couldn't insert the data into the DDBB.");
            
            $success = 1;
        }

        else{
            $error = 1;
        }
    }
?>
Dovendo inserire la verifica recaptcha di Google
Codice:
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=__PRIVATE_KEY__&response='.$_POST['g-recaptcha-response'].'&remoteip='.$_SERVER['REMOTE_ADDR']);
$responseDecoded  = json_decode($response);
if ( $responseDecoded->success == false ) {
  echo 'Busted!';
  exit();
}
Dove inserisco questo codice ?

Grazie per l'aiuto
 

giumazzi

Nuovo Utente
16 Feb 2017
27
2
3
provincia PESARO
[RISOLTO]

Ho inserito il codice in questa posizione

PHP:
<?php

    $error = 0;
    $success = 0;


    //verify captcha
    if (isset($_POST['register']) && $_POST['g-recaptcha-response']!="")
{
 $secret = 'SECRET CODE';
 $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);

 $responseData = json_decode($verifyResponse);
 if($responseData->success)
{

        $lastname = $_POST["last_name"];
......
.....