Showing posts with label Web API. Show all posts
Showing posts with label Web API. Show all posts

Thursday, September 28, 2017

Coinhive: Capcha Example: Using PHP

<html>
<head></head>
<body>
<div>
<?php
if(isset($_POST["coinhive-captcha-token"])){
        $token = $_POST["coinhive-captcha-token"];
        $secret = 'bAbbbb5A9AbA0bbbA3bAAbAb8bAbAAAb';
        $url = 'https://api.coinhive.com/token/verify';

        $data = array('token'=> $token,
                      'hashes' => 1024,
                      'secret' => $secret);

        $options = array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data)
        );
     
        $context  = stream_context_create(array('http' => $options));

        $response = json_decode(file_get_contents($url, false, $context));

        if ($result === FALSE) {
                echo "Error";
                exit;
        }
     
        $responseSuccess = $response->success;
}
?>
<?php if ($responseSuccess){ ?>
Verified<br/>
<?php } else { ?>
You must verify
<form action="?" method="post">
        <!-- other form fields -->

        <script src="https://coinhive.com/lib/captcha.min.js" async></script>
        <div class="coinhive-captcha" data-hashes="1024" data-key="AAAbAA33bAAbAbbAbAA4bA7dA4AAbA7b"></div>

        <input type="submit" value="Submit"/>
</form>
<?php } ?>
</div>
</body>
</html>