summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhass2017-03-20 14:56:32 (GMT)
committerhass2017-03-20 14:56:32 (GMT)
commit5c4d7d596d540e8dc366a8220c313fedf15acfd5 (patch)
tree10e4751a105deb937a7ef1532f529c0499e7ee57
parent8e7eab244f9029b8f25312ad0103b422599b12b6 (diff)
Update reCAPTCHA lib from 1.1.2 to 1.1.3
-rw-r--r--recaptcha-php/.travis.yml9
-rw-r--r--recaptcha-php/CONTRIBUTING.md2
-rw-r--r--recaptcha-php/README.md4
-rw-r--r--recaptcha-php/composer.json4
-rw-r--r--recaptcha-php/examples/example-captcha.php20
-rw-r--r--recaptcha-php/src/ReCaptcha/ReCaptcha.php7
-rw-r--r--recaptcha-php/src/ReCaptcha/RequestMethod/Post.php2
-rw-r--r--recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php3
-rw-r--r--recaptcha-php/src/ReCaptcha/RequestMethod/SocketPost.php2
-rw-r--r--recaptcha-php/src/ReCaptcha/Response.php30
-rw-r--r--recaptcha-php/src/autoload.php2
-rw-r--r--recaptcha-php/tests/ReCaptcha/ResponseTest.php28
12 files changed, 76 insertions, 37 deletions
diff --git a/recaptcha-php/.travis.yml b/recaptcha-php/.travis.yml
index fb25bad..a7da54d 100644
--- a/recaptcha-php/.travis.yml
+++ b/recaptcha-php/.travis.yml
@@ -3,11 +3,12 @@ language: php
sudo: false
php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
+ - '5.5'
+ - '5.6'
+ - '7.0'
+ - '7.1'
- hhvm
+ - nightly
before_script:
- composer install
diff --git a/recaptcha-php/CONTRIBUTING.md b/recaptcha-php/CONTRIBUTING.md
index 1ba8539..110ec21 100644
--- a/recaptcha-php/CONTRIBUTING.md
+++ b/recaptcha-php/CONTRIBUTING.md
@@ -17,7 +17,7 @@ frustration later on.
### Code reviews
All submissions, including submissions by project members, require review. We
-use Github pull requests for this purpose.
+use GitHub pull requests for this purpose.
### The small print
Contributions made by corporations are covered by a different agreement than
diff --git a/recaptcha-php/README.md b/recaptcha-php/README.md
index 6e81a8e..7984adf 100644
--- a/recaptcha-php/README.md
+++ b/recaptcha-php/README.md
@@ -6,7 +6,7 @@
* Project page: http://www.google.com/recaptcha/
* Repository: https://github.com/google/recaptcha
-* Version: 1.1.2
+* Version: 1.1.3
* License: BSD, see [LICENSE](LICENSE)
## Description
@@ -83,6 +83,8 @@ $recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// verified!
+ // if Domain Name Validation turned off don't forget to check hostname field
+ // if($resp->getHostName() === $_SERVER['SERVER_NAME']) { }
} else {
$errors = $resp->getErrorCodes();
}
diff --git a/recaptcha-php/composer.json b/recaptcha-php/composer.json
index 63b751c..1b41db8 100644
--- a/recaptcha-php/composer.json
+++ b/recaptcha-php/composer.json
@@ -10,10 +10,10 @@
"source": "https://github.com/google/recaptcha"
},
"require": {
- "php": ">=5.3.2"
+ "php": ">=5.5"
},
"require-dev": {
- "phpunit/phpunit": "4.5.*"
+ "phpunit/phpunit": "^4.8"
},
"autoload": {
"psr-4": {
diff --git a/recaptcha-php/examples/example-captcha.php b/recaptcha-php/examples/example-captcha.php
index 8875171..f636cc1 100644
--- a/recaptcha-php/examples/example-captcha.php
+++ b/recaptcha-php/examples/example-captcha.php
@@ -62,18 +62,18 @@ $lang = 'en';
<h1>reCAPTCHA Example</h1>
<?php if ($siteKey === '' || $secret === ''): ?>
<h2>Add your keys</h2>
- <p>If you do not have keys already then visit <tt>
+ <p>If you do not have keys already then visit <kbd>
<a href = "https://www.google.com/recaptcha/admin">
- https://www.google.com/recaptcha/admin</a></tt> to generate them.
- Edit this file and set the respective keys in <tt>$siteKey</tt> and
- <tt>$secret</tt>. Reload the page after this.</p>
+ https://www.google.com/recaptcha/admin</a></kbd> to generate them.
+ Edit this file and set the respective keys in <kbd>$siteKey</kbd> and
+ <kbd>$secret</kbd>. Reload the page after this.</p>
<?php
elseif (isset($_POST['g-recaptcha-response'])):
// The POST data here is unfiltered because this is an example.
// In production, *always* sanitise and validate your input'
?>
- <h2><tt>POST</tt> data</h2>
- <tt><pre><?php var_export($_POST); ?></pre></tt>
+ <h2><kbd>POST</kbd> data</h2>
+ <kbd><pre><?php var_export($_POST); ?></pre></kbd>
<?php
// If the form submission includes the "g-captcha-response" field
// Create an instance of the service using your secret
@@ -95,16 +95,16 @@ elseif (isset($_POST['g-recaptcha-response'])):
<p><a href="/">Try again</a></p>
<?php
else:
-// If it's not successfull, then one or more error codes will be returned.
+// If it's not successful, then one or more error codes will be returned.
?>
<h2>Something went wrong</h2>
<p>The following error was returned: <?php
foreach ($resp->getErrorCodes() as $code) {
- echo '<tt>' , $code , '</tt> ';
+ echo '<kbd>' , $code , '</kbd> ';
}
?></p>
- <p>Check the error code reference at <tt><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></tt>.
- <p><strong>Note:</strong> Error code <tt>missing-input-response</tt> may mean the user just didn't complete the reCAPTCHA.</p>
+ <p>Check the error code reference at <kbd><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></kbd>.
+ <p><strong>Note:</strong> Error code <kbd>missing-input-response</kbd> may mean the user just didn't complete the reCAPTCHA.</p>
<p><a href="/">Try again</a></p>
<?php
endif;
diff --git a/recaptcha-php/src/ReCaptcha/ReCaptcha.php b/recaptcha-php/src/ReCaptcha/ReCaptcha.php
index e2f7c34..bda769c 100644
--- a/recaptcha-php/src/ReCaptcha/ReCaptcha.php
+++ b/recaptcha-php/src/ReCaptcha/ReCaptcha.php
@@ -35,16 +35,16 @@ class ReCaptcha
* Version of this client library.
* @const string
*/
- const VERSION = 'php_1.1.2';
+ const VERSION = 'php_1.1.3';
/**
* Shared secret for the site.
- * @var type string
+ * @var string
*/
private $secret;
/**
- * Method used to communicate with service. Defaults to POST request.
+ * Method used to communicate with service. Defaults to POST request.
* @var RequestMethod
*/
private $requestMethod;
@@ -54,6 +54,7 @@ class ReCaptcha
*
* @param string $secret shared secret between site and reCAPTCHA server.
* @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
+ * @throws \RuntimeException if $secret is invalid
*/
public function __construct($secret, RequestMethod $requestMethod = null)
{
diff --git a/recaptcha-php/src/ReCaptcha/RequestMethod/Post.php b/recaptcha-php/src/ReCaptcha/RequestMethod/Post.php
index 7770d90..01ab33b 100644
--- a/recaptcha-php/src/ReCaptcha/RequestMethod/Post.php
+++ b/recaptcha-php/src/ReCaptcha/RequestMethod/Post.php
@@ -58,7 +58,7 @@ class Post implements RequestMethod
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $params->toQueryString(),
- // Force the peer to validate (not needed in 5.6.0+, but still works
+ // Force the peer to validate (not needed in 5.6.0+, but still works)
'verify_peer' => true,
// Force the peer validation to use www.google.com
$peer_key => 'www.google.com',
diff --git a/recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php b/recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php
index d3c8792..f51f123 100644
--- a/recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php
+++ b/recaptcha-php/src/ReCaptcha/RequestMethod/Socket.php
@@ -51,9 +51,8 @@ class Socket
if ($this->handle != false && $errno === 0 && $errstr === '') {
return $this->handle;
- } else {
- return false;
}
+ return false;
}
/**
diff --git a/recaptcha-php/src/ReCaptcha/RequestMethod/SocketPost.php b/recaptcha-php/src/ReCaptcha/RequestMethod/SocketPost.php
index 4754121..45bee0e 100644
--- a/recaptcha-php/src/ReCaptcha/RequestMethod/SocketPost.php
+++ b/recaptcha-php/src/ReCaptcha/RequestMethod/SocketPost.php
@@ -32,7 +32,7 @@ use ReCaptcha\RequestParameters;
/**
* Sends a POST request to the reCAPTCHA service, but makes use of fsockopen()
* instead of get_file_contents(). This is to account for people who may be on
- * servers where allow_furl_open is disabled.
+ * servers where allow_url_open is disabled.
*/
class SocketPost implements RequestMethod
{
diff --git a/recaptcha-php/src/ReCaptcha/Response.php b/recaptcha-php/src/ReCaptcha/Response.php
index d2d8a8b..4d4d036 100644
--- a/recaptcha-php/src/ReCaptcha/Response.php
+++ b/recaptcha-php/src/ReCaptcha/Response.php
@@ -32,7 +32,7 @@ namespace ReCaptcha;
class Response
{
/**
- * Succes or failure.
+ * Success or failure.
* @var boolean
*/
private $success = false;
@@ -44,6 +44,12 @@ class Response
private $errorCodes = array();
/**
+ * The hostname of the site where the reCAPTCHA was solved.
+ * @var string
+ */
+ private $hostname;
+
+ /**
* Build the response from the expected JSON returned by the service.
*
* @param string $json
@@ -57,15 +63,17 @@ class Response
return new Response(false, array('invalid-json'));
}
+ $hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null;
+
if (isset($responseData['success']) && $responseData['success'] == true) {
- return new Response(true);
+ return new Response(true, array(), $hostname);
}
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
- return new Response(false, $responseData['error-codes']);
+ return new Response(false, $responseData['error-codes'], $hostname);
}
- return new Response(false);
+ return new Response(false, array(), $hostname);
}
/**
@@ -73,11 +81,13 @@ class Response
*
* @param boolean $success
* @param array $errorCodes
+ * @param string $hostname
*/
- public function __construct($success, array $errorCodes = array())
+ public function __construct($success, array $errorCodes = array(), $hostname = null)
{
$this->success = $success;
$this->errorCodes = $errorCodes;
+ $this->hostname = $hostname;
}
/**
@@ -99,4 +109,14 @@ class Response
{
return $this->errorCodes;
}
+
+ /**
+ * Get hostname.
+ *
+ * @return string
+ */
+ public function getHostname()
+ {
+ return $this->hostname;
+ }
}
diff --git a/recaptcha-php/src/autoload.php b/recaptcha-php/src/autoload.php
index a53cbd7..5a7ee94 100644
--- a/recaptcha-php/src/autoload.php
+++ b/recaptcha-php/src/autoload.php
@@ -1,6 +1,6 @@
<?php
-/* An autoloader for ReCaptcha\Foo classes. This should be require()d
+/* An autoloader for ReCaptcha\Foo classes. This should be required()
* by the user before attempting to instantiate any of the ReCaptcha
* classes.
*/
diff --git a/recaptcha-php/tests/ReCaptcha/ResponseTest.php b/recaptcha-php/tests/ReCaptcha/ResponseTest.php
index 0e7eac9..f6075d7 100644
--- a/recaptcha-php/tests/ReCaptcha/ResponseTest.php
+++ b/recaptcha-php/tests/ReCaptcha/ResponseTest.php
@@ -32,21 +32,26 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider provideJson
*/
- public function testFromJson($json, $success, $errorCodes)
+ public function testFromJson($json, $success, $errorCodes, $hostname)
{
$response = Response::fromJson($json);
$this->assertEquals($success, $response->isSuccess());
$this->assertEquals($errorCodes, $response->getErrorCodes());
+ $this->assertEquals($hostname, $response->getHostname());
}
public function provideJson()
{
return array(
- array('{"success": true}', true, array()),
- array('{"success": false, "error-codes": ["test"]}', false, array('test')),
- array('{"success": true, "error-codes": ["test"]}', true, array()),
- array('{"success": false}', false, array()),
- array('BAD JSON', false, array('invalid-json')),
+ array('{"success": true}', true, array(), null),
+ array('{"success": true, "hostname": "google.com"}', true, array(), 'google.com'),
+ array('{"success": false, "error-codes": ["test"]}', false, array('test'), null),
+ array('{"success": false, "error-codes": ["test"], "hostname": "google.com"}', false, array('test'), 'google.com'),
+ array('{"success": true, "error-codes": ["test"]}', true, array(), null),
+ array('{"success": true, "error-codes": ["test"], "hostname": "google.com"}', true, array(), 'google.com'),
+ array('{"success": false}', false, array(), null),
+ array('{"success": false, "hostname": "google.com"}', false, array(), 'google.com'),
+ array('BAD JSON', false, array('invalid-json'), null),
);
}
@@ -57,6 +62,9 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
$response = new Response(false);
$this->assertFalse($response->isSuccess());
+
+ $response = new Response(true, array(), 'example.com');
+ $this->assertEquals('example.com', $response->getHostName());
}
public function testGetErrorCodes()
@@ -65,4 +73,12 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
$response = new Response(true, $errorCodes);
$this->assertEquals($errorCodes, $response->getErrorCodes());
}
+
+ public function testGetHostname()
+ {
+ $hostname = 'google.com';
+ $errorCodes = array();
+ $response = new Response(true, $errorCodes, $hostname);
+ $this->assertEquals($hostname, $response->getHostname());
+ }
}