1 | <?php |
||
35 | class Post implements RequestMethod |
||
36 | { |
||
37 | /** |
||
38 | * URL to which requests are POSTed. |
||
39 | * @const string |
||
40 | */ |
||
41 | const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
||
42 | |||
43 | /** |
||
44 | * Submit the POST request with the specified parameters. |
||
45 | * |
||
46 | * @param RequestParameters $params Request parameters |
||
47 | * @return string Body of the reCAPTCHA response |
||
48 | */ |
||
49 | public function submit(RequestParameters $params) |
||
50 | { |
||
51 | /** |
||
52 | * PHP 5.6.0 changed the way you specify the peer name for SSL context options. |
||
53 | * Using "CN_name" will still work, but it will raise deprecated errors. |
||
54 | */ |
||
55 | $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; |
||
56 | $options = array( |
||
57 | 'http' => array( |
||
58 | 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
||
59 | 'method' => 'POST', |
||
60 | 'content' => $params->toQueryString(), |
||
61 | // Force the peer to validate (not needed in 5.6.0+, but still works |
||
62 | 'verify_peer' => true, |
||
63 | // Force the peer validation to use www.google.com |
||
64 | $peer_key => 'www.google.com', |
||
65 | ), |
||
66 | ); |
||
67 | $context = stream_context_create($options); |
||
68 | return file_get_contents(self::SITE_VERIFY_URL, false, $context); |
||
69 | } |
||
70 | } |
||
71 |