NoCaptcha returning error invalid-json
I had the same issue and fixed it by using cURL as request method instead POST.
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
The key to the solution was to simply turn on the php errors (I know, it's embarrassing). This delivered the error that kept me struggling and also delivered the solution at the same time:
PHP had problems connecting to the https verifying page of google. That was just because of a single option in the php.ini: allow_url_fopen
php.net description:
allow_url_fopen boolean
This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.
Changing its value from 0 to 1 solved my problem. Shows even more how important it is to turn on php errors when developing (I am a super noob to php programming)
Hope this helps somebody some time!
This solved it for me:
//$recaptcha = new \ReCaptcha\ReCaptcha($secret);
// If file_get_contents() is locked down on your PHP installation to disallow
// its use with URLs, then you can use the alternative request method instead.
// This makes use of fsockopen() instead.
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());