1 <?php
2 namespace DevStrefa\ReCaptcha\Senders;
3
4 use DevStrefa\ReCaptcha\Response;
5
6 7 8 9 10 11 12 13 14
15 class FgcSender implements \DevStrefa\ReCaptcha\Senders\SenderInterface
16 {
17 18 19
20 const ENDPOINT='https://www.google.com/recaptcha/api/siteverify';
21
22
23 24 25 26 27 28 29 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