I'm a google recaptcha v2 on a local machine running wamp. Everything looks fine except it keeps dying when its supposed to validate the form
I'm getting this error:
Fatal error: Class 'ReCaptcha\RequestMethod\Post' not found in C:\wamp\www\php\contactForm\Captcha\ReCaptcha.php on line 73
I've pretty much copy/pasted the example code from google:
if (!empty($human)) {
require_once('Captcha\ReCaptcha.php');
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($human, $remoteIp);
if ($resp->isSuccess()) {
// verified!
I've downloaded the files from the google github (https://github.com/google/recaptcha/tree/master/src/ReCaptcha) and just used the folder /files names as they came. I've got my validation file one folder above but I've also tried coping the files into the same folder as my validation script just in case.
Any ideas?
I hope I don't get slammed to hard but I found if you require all of the files it works as designed without using an autoloader or composer.
It seems google bank on the fact that everyone use composer to install their repository. And to be honest that is the only installation method they give on thier github repo readme.md https://github.com/google/recaptcha
When you install a package such as google recaptcha with composer the package has the option to register with an autoloader in https://github.com/google/recaptcha/blob/master/composer.json
This way all you have to include in your script to get access to all your package classes is the autoload.php that composer generates when it installs your packages.
Line 34: https://github.com/google/recaptcha/blob/master/examples/example-captcha.php
An autoloader is a function that tries to load a class when php is asked for it. And in this case it kind of maps a namespace to a directory structure on the disk.
More about php autoloaders here: http://php.net/autoload and here: http://www.php-fig.org/psr/psr-4/examples/
If you do not wish to use composer and its autoload functionality, you may find this useful: https://github.com/abraham/twitteroauth it has an autoload.php which you could borrow which can load classes without composer.
$prefix = 'ReCaptcha\\';
$base_dir = __DIR__ . '/src/ReCaptcha/';
new ReCaptcha\ReCaptcha($RECAPTCHASECRETKEY);