ReCaptcha
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • DevStrefa
    • ReCaptcha
      • Senders

Classes

  • DevStrefa\ReCaptcha\ReCaptcha
  • DevStrefa\ReCaptcha\Response
  • DevStrefa\ReCaptcha\Senders\FgcSender

Interfaces

  • DevStrefa\ReCaptcha\Senders\SenderInterface
 1 <?php
 2 namespace DevStrefa\ReCaptcha\Senders;
 3 
 4 use DevStrefa\ReCaptcha\Response;
 5 
 6 /**
 7  * File Get Contents Sender
 8  * 
 9  * This is very simple implementation of SenderInterface it's using php file_get_contents function to get response from reCaptcha endpoint
10  * 
11  * @author Cichy <d3ut3r@gmail.com>  
12  * @license https://opensource.org/licenses/MIT MIT
13  * @version 1.0.0
14  */
15 class FgcSender implements \DevStrefa\ReCaptcha\Senders\SenderInterface
16 {
17     /**
18      * Contains url to google verify service
19      */
20     const ENDPOINT='https://www.google.com/recaptcha/api/siteverify';
21 
22     
23     /**
24      * Make request and return Response Object
25      * 
26      * @param string $secret
27      * @param string $response
28      * @param string $remoteIp
29      * @return Response Response Object
30      */
31     public function send($secret, $response, $remoteIp)
32     {
33 
34         $postData = array(
35             'secret' => $secret,
36             'response' => $response,
37         );
38 
39         if (!empty($remoteIp))
40         {
41             $postData['remoteip'] = $remoteIp;
42         }
43 
44         $context_options = array(
45             'http' =>
46                 array(
47                     'method' => 'POST',
48                     'header' => 'Content-type: application/x-www-form-urlencoded',
49                     'content' => http_build_query($postData)
50                 )
51         );
52         
53         $context=  stream_context_create($context_options);
54         return new Response(file_get_contents(self::ENDPOINT,FALSE,$context));
55     }
56 }
57 
ReCaptcha API documentation generated by ApiGen