Jump to content

Google reCAPTCHA V2 Response Error


Donation

Recommended Posts

Why am I getting that error on Google reCAPTCHA V2 response?

Hello, it's my first time posting here and I'm not good with such stuff as the one I'm posting right now

I have been trying to solve this issue for 2 days by now so I could use some help lol

This error "Please solve the captcha." is showing even if the captcha is verified so it's showing in the both cases (verified/unverified).

Thanks in advance.


>> PHP Part:

<?php

require_once 'db/setting.php';
require_once 'db/odbc.php';

session_start();
error_reporting(0);

if (isset($_SERVER['HTTPS']) &&
    ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
    isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
    $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
  $protocol = 'https://';
}
else {
  $protocol = 'http://';
}
$currentDomain = $protocol.$_SERVER[HTTP_HOST];

$API["secret_key"] = "xx";
$API["api_key"] = "xx";
$API["callback"] = $currentDomain."/vote-reward-tok.php?return={RETURNEDCODE}";
$API["API_Domain"] = "http://api.top-kal.com";

$secretKey = 'xxx';
$captcha = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];
$responseData=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&responseData=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($responseData,true);

$config["db_username"] = "sa";
$config["db_password"] = "********";
$config["db_database_account"] = "kal_auth";
$config["db_database_player"] = "kal_db";
$config["db_server"] = "NAME\SQLEXPRESS";
$config["db_driver"] = "SQL Server";

$config["Reward_Name"] = "Vote Coin";
$config["MinLvl_Require"] = 30;
$config["Reward_Index"] = 447;
$config["Reward_Amount"] = 10;
$config["Reward_Bound"] = false;


>> SQL Part

function insertRewards($account_unique_id){
    global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']);
    
    if(!$connect)
        return false;

    $query = odbc_exec($connect,"SELECT Top 1 [IID] FROM [Item] Where [IID] < 1 order by IID Desc");
    if(!$query)
        return false;

    $data = odbc_fetch_array($query);
    if($data && !empty($data) && isset($data["IID"]))
        odbc_exec($connect,"INSERT INTO [Item] ([PID],[IID],[Index],[Prefix],[Info],[Num])VALUES ($account_unique_id,".($data["IID"]+1).",".$config["Reward_Index"].",0,".(16+($config["Reward_Bound"] ? 128 : 0)).",".$config["Reward_Amount"].")");
    
}

function checkCharacters($accountUID){
    global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_player"].';', $config['db_username'] ,$config['db_password']);
    
    if(!$connect)
        return array("error" => "failed to connect to database players.");

    $query = odbc_exec($connect,"SELECT [Level] FROM [Player] WHERE [UID] = $accountUID ORDER BY [Level] DESC");
    if(!$query)
        return array("error" => "failed to find characters in this account id.");

    while($r = odbc_fetch_array($query)){
        if($r["Level"]  >= $config["MinLvl_Require"])
        return array("success" => $accountUID);
    }
  return array("error" => "You should have one character at least higher than level : ".$config["MinLvl_Require"]." to vote.");
}

function checkAccount($accountID){
    global $config;

    $connect = odbc_connect('Driver={'.$config["db_driver"].'};Server='.$config["db_server"].';Database='.$config["db_database_account"].';', $config['db_username'] ,$config['db_password']);
    
    if(!$connect)
        return array("error" => "failed to connect to database accounts.");

    $query = odbc_exec($connect,"SELECT TOP 1 [UID] FROM [Login] WHERE [ID] = '$accountID'");
    if(!$query)
        return array("error" => "this account id not exists.");

    $data = odbc_fetch_array($query);
    if(!$data || empty($data) || !isset($data["UID"]))
        return array("error" => "this account id not exists.");

    if($config["MinLvl_Require"] > 0)
          return checkCharacters($data["UID"]);
      
  return array("success" => $data["UID"]);
}

>> Submitting Function

$response = array("error" => false , "success" => false , 'redirect' => false);

function post_content($query){
$query_array = array();foreach( $query as $key => $key_value )$query_array[] = urlencode( $key ) . '=' . urlencode( $key_value );return implode( '&', $query_array );
}

    global $API;
    $opts = array('http' =>  array('method'  => 'POST',"header" => "Content-type: application/x-www-form-urlencoded\r\nAuthorization:".base64_encode($API["api_key"].":".$API["secret_key"])."\r\n", "content" => post_content($content)));return stream_context_create($opts);
}

function submit(){
    global $API;

    if(empty($captcha) || $captcha == '' || !isset($captcha))
        return array(    "error" => "Please solve the captcha.");
    
    if (empty($_POST['account']) || !ctype_alnum($_POST['account']))
        return array(    "error" => "Invalid account id.");
        
    $checkAccount = checkAccount($_POST['account']);

    if (isset($checkAccount["error"]))
        return array("error" => $checkAccount["error"]);

    if (isset($checkAccount["success"])){
        $account_unique_id = (isset($_SESSION['kal_id'])) ? $_SESSION['kal_id'] : $checkAccount["success"]; 
        $result = json_decode(file_get_contents($API["API_Domain"] . '/api/generate/vote-rewards-token', false, postParams(array('callback' => $API["callback"],'account_unique_id' => $account_unique_id    ))) , true);
            {
        echo '<br><center><h3>Please wait...</h3></center>';
    }
        if (!empty($result)){
            if (isset($result["response"])){
                if (isset($result["response"]["error"]))
                    return array("error" => $result["response"]["error"]);
                elseif (isset($result["response"]["success"]))
                    return array("redirect" => '<script type="text/javascript">setTimeout(function () { window.location.href = "'.$result["response"]["success"].'";}, 500)</script>');
            }
        }
    }
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['account'])){
    $response = submit();
    if (isset($response['redirect']) && $response['redirect']){
        echo $response['redirect'];
        die;
        }
}elseif (isset($_GET['return'])){
    $result = json_decode(file_get_contents($API["API_Domain"] . '/api/verify/vote-rewards-token', false, postParams(array('returned_code' => $_GET['return']))) , true);
    if (!empty($result)){
        if (isset($result["response"])){
            if (isset($result["response"]["error"]))
                $response['error'] = $result["response"]["error"];
            elseif (isset($result["response"]["success"])){
                insertRewards($result["response"]["account_unique_id"]);
                $response['success'] = '<b>Thank you, Your vote has been recorded and the server rank will be updated soon.<b><br />You will receive your rewards in storage of your account.<p>Your next vote in : <b>' . $result["response"]["NextVote"] . '</b></p>';
                }
            }
        }
    }
?>


>> HTML part:

<head>
<title>Vote Rewards - <?php echo $config['serverName']; ?></title>
<link rel="shortcut icon" href=images/favicon.png"> 
<link rel="stylesheet" href="css/vote.css">
<link rel="stylesheet" href="css/fontawesome.css">
<link rel="stylesheet" href="css/fontawesomeall.css">
<script src='https://www.google.com/recaptcha/api.js'></script>

</head>
<body>
<form class="vote-form" method="post">
<noscript><div class="isa_error">Javascript is not enabled in your browser! Please enable it or change your browser.</div></noscript>
<?php if(isset($response['error']) && $response['error']){ ?><div class="isa_error"> <?php echo $response['error'] ;?> </div> <?php } ?>
<?php if(isset($response['success']) && $response['success']){ ?><div class="isa_success"> <?php echo $response['success'] ;?> </div>
<?php }else{ ?>
    <label>
        <span>Account ID :</span>
        <input  type="text" name="account" maxlength="20" <?php echo (isset($_SESSION['kal_username'])) ? 'readonly value="'.$_SESSION['kal_username'].'"' : ""; ?>" />
    </label>
    <div class="g-recaptcha" style="margin:0 auto;" data-sitekey="xxx" data-theme="dark"></div>
     <label class="label_btn">
        <input type="submit" class="button" value="Vote" /> 
    </label> 
<?php } ?>    
</form>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</body>
</html>

 

Edited by requinix
we don't do markdown. please use the Code <> button for code
Link to comment
Share on other sites

function submit(){
    global $API;

    if(empty($captcha) || $captcha == '' || !isset($captcha))

Variables defined outside functions are not available inside functions. They should be passed in as function arguments, like you're doing with post_content() and $query.

Link to comment
Share on other sites

Are you not getting syntax errors with this? From my formatting of the code, you've got mismatched braces all over the place. It's hard to tell because you're bouncing between using braces and not (please stop doing that), but it looks like there are some nesting issues going on unless I'm mistaken.

<?php
$response = array("error" => false , "success" => false , 'redirect' => false);

function post_content($query){
  $query_array = array();
  foreach( $query as $key => $key_value )
    $query_array[] = urlencode( $key ) . '=' . urlencode( $key_value );
  
  return implode( '&', $query_array );
}

global $API;
$opts = array('http' =>  array('method'  => 'POST',"header" => "Content-type: application/x-www-form-urlencoded\r\nAuthorization:".base64_encode($API["api_key"].":".$API["secret_key"])."\r\n", "content" => post_content($content)));

return stream_context_create($opts);  // WHAT ARE YOU RETURNING FROM?

}   //WHERE DOES THIS START?

function submit(){
  global $API;

  if(empty($captcha) || $captcha == '' || !isset($captcha))
    return array(    "error" => "Please solve the captcha.");

  if (empty($_POST['account']) || !ctype_alnum($_POST['account']))
    return array(    "error" => "Invalid account id.");
      
  $checkAccount = checkAccount($_POST['account']);

  if (isset($checkAccount["error"]))
    return array("error" => $checkAccount["error"]);

  if (isset($checkAccount["success"])){
    $account_unique_id = (isset($_SESSION['kal_id'])) ? $_SESSION['kal_id'] : $checkAccount["success"]; 
    $result = json_decode(file_get_contents($API["API_Domain"] . '/api/generate/vote-rewards-token', false, postParams(array('callback' => $API["callback"],'account_unique_id' => $account_unique_id    ))) , true);

  { // WHAT IS THIS FOR?

    echo '<br><center><h3>Please wait...</h3></center>';
  }
  if (!empty($result)){
    if (isset($result["response"])){
      if (isset($result["response"]["error"]))
        return array("error" => $result["response"]["error"]);

      elseif (isset($result["response"]["success"]))
        return array("redirect" => '<script type="text/javascript">setTimeout(function () { window.location.href = "'.$result["response"]["success"].'";}, 500)</script>');

    }
  }
  } //  WHAT?
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['account'])){
  $response = submit();
  if (isset($response['redirect']) && $response['redirect']){
    echo $response['redirect'];
    die;
  }
}elseif (isset($_GET['return'])){
  $result = json_decode(file_get_contents($API["API_Domain"] . '/api/verify/vote-rewards-token', false, postParams(array('returned_code' => $_GET['return']))) , true);
  if (!empty($result)){
    if (isset($result["response"])){
      if (isset($result["response"]["error"]))
        $response['error'] = $result["response"]["error"];

      elseif (isset($result["response"]["success"])){
        insertRewards($result["response"]["account_unique_id"]);
        $response['success'] = '<b>Thank you, Your vote has been recorded and the server rank will be updated soon.<b><br />You will receive your rewards in storage of your account.<p>Your next vote in : <b>' . $result["response"]["NextVote"] . '</b></p>';
      }
    }
  }
}
?>

 

Link to comment
Share on other sites

7 hours ago, requinix said:

function submit(){
    global $API;

    if(empty($captcha) || $captcha == '' || !isset($captcha))

Variables defined outside functions are not available inside functions. They should be passed in as function arguments, like you're doing with post_content() and $query.

Hey, I'll try that out thank you

Link to comment
Share on other sites

4 hours ago, maxxd said:

Are you not getting syntax errors with this? From my formatting of the code, you've got mismatched braces all over the place. It's hard to tell because you're bouncing between using braces and not (please stop doing that), but it looks like there are some nesting issues going on unless I'm mistaken.


<?php
$response = array("error" => false , "success" => false , 'redirect' => false);

function post_content($query){
  $query_array = array();
  foreach( $query as $key => $key_value )
    $query_array[] = urlencode( $key ) . '=' . urlencode( $key_value );
  
  return implode( '&', $query_array );
}

global $API;
$opts = array('http' =>  array('method'  => 'POST',"header" => "Content-type: application/x-www-form-urlencoded\r\nAuthorization:".base64_encode($API["api_key"].":".$API["secret_key"])."\r\n", "content" => post_content($content)));

return stream_context_create($opts);  // WHAT ARE YOU RETURNING FROM?

}   //WHERE DOES THIS START?

function submit(){
  global $API;

  if(empty($captcha) || $captcha == '' || !isset($captcha))
    return array(    "error" => "Please solve the captcha.");

  if (empty($_POST['account']) || !ctype_alnum($_POST['account']))
    return array(    "error" => "Invalid account id.");
      
  $checkAccount = checkAccount($_POST['account']);

  if (isset($checkAccount["error"]))
    return array("error" => $checkAccount["error"]);

  if (isset($checkAccount["success"])){
    $account_unique_id = (isset($_SESSION['kal_id'])) ? $_SESSION['kal_id'] : $checkAccount["success"]; 
    $result = json_decode(file_get_contents($API["API_Domain"] . '/api/generate/vote-rewards-token', false, postParams(array('callback' => $API["callback"],'account_unique_id' => $account_unique_id    ))) , true);

  { // WHAT IS THIS FOR?

    echo '<br><center><h3>Please wait...</h3></center>';
  }
  if (!empty($result)){
    if (isset($result["response"])){
      if (isset($result["response"]["error"]))
        return array("error" => $result["response"]["error"]);

      elseif (isset($result["response"]["success"]))
        return array("redirect" => '<script type="text/javascript">setTimeout(function () { window.location.href = "'.$result["response"]["success"].'";}, 500)</script>');

    }
  }
  } //  WHAT?
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['account'])){
  $response = submit();
  if (isset($response['redirect']) && $response['redirect']){
    echo $response['redirect'];
    die;
  }
}elseif (isset($_GET['return'])){
  $result = json_decode(file_get_contents($API["API_Domain"] . '/api/verify/vote-rewards-token', false, postParams(array('returned_code' => $_GET['return']))) , true);
  if (!empty($result)){
    if (isset($result["response"])){
      if (isset($result["response"]["error"]))
        $response['error'] = $result["response"]["error"];

      elseif (isset($result["response"]["success"])){
        insertRewards($result["response"]["account_unique_id"]);
        $response['success'] = '<b>Thank you, Your vote has been recorded and the server rank will be updated soon.<b><br />You will receive your rewards in storage of your account.<p>Your next vote in : <b>' . $result["response"]["NextVote"] . '</b></p>';
      }
    }
  }
}
?>

 

I didn't code it to be honest, it was released online (without google recaptcha)
And no I'm not actually getting any syntax errors
Here is the original code where I got it : https://top-kal.com/api-docs/Kal-Online 
Thanks for answering though (:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.