F
F
felsme2018-12-27 11:10:59
PHP
felsme, 2018-12-27 11:10:59

VK API captcha not sent correctly?

Why do I send the answer to the captcha, and he only answers me with a new captcha

function friends_add () {
   global $token;
   global $userid;
   foreach ($userid as $item) {
   	$url = "https://api.vk.com/method/friends.add?user_id=$item&access_token=$token&v=5.92";
   	$ch = curl_init($url);
   	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   	$res = curl_exec($ch);
   	curl_close($ch);
   	$res = json_decode($res, true);
   	if ($res['response'] == 1) {
   		echo "Заявка $item отправлена<br>";
   	} else if ($res['error']['error_code'] == 14) {
      $sid = $res['error']['captcha_sid'];
   		echo "<img src=\"http:\/\/api.vk.com\/captcha.php?sid={$sid}&s=1\" alt=\"\">";
   		echo '<form name="form" method="post"> <input type="text" name="cap" id="cap"> </form>';
   		$cap_ans = $_POST['cap'];
   		if (!empty($_POST['cap'])) {
   			$url = "https://api.vk.com/method/friends.add?user_id=$item&captcha_sid=$sid&captcha_key=$cap_ans&access_token=$token&v=5.92";
   			$ch = curl_init($url);
   			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   			$res = curl_exec($ch);
   			curl_close($ch);
   			$res = json_decode($res, true);
   			var_dump($res);
   			break;
   		}
   		
}

}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zax2002, 2019-01-02
@felsme

When there is a 'cap' field in POST, the image is loaded again anyway. Do this:
if(!empty($_POST['cap'])) {
...
} else {
echo(captcha);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question