Google recaptcha when posting to different server - recaptcha

I have a form with recaptcha V2:
https://www.fisherwallace.com/pages/do-you-qualify-to-use-the-device
It posts to a different server and then redirects back to a different page on the server with the recaptcha form.
Recaptcha site says: "We detected that your site is not verifying reCAPTCHA solutions." I assume it's due to posting to the different server.
NOTE: You'll see I have a clumsy workaround at the moment to address the fact that the recaptcha does not challenge automatically. Without the workaround, the recaptcha is there but nothing happens on submit.
I found some sample PHP code for the server side...
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}
if(isset($_POST['comment'])){
$comment=$_POST['comment'];
}
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
if($responseKeys["success"]) {
echo '<h2>Thanks for posting comment</h2>';
} else {
echo '<h2>You are spammer ! Get the #$%K out</h2>';
}
Clearly lots of this code is moot since the user does not actually load the POST server page.
But will this part get the callback recaptcha needs?
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
If the IP is a mismatch, can i hard code it using the IP from the originating server?

IP is optional
You need to do file_get_contents 'method' => 'POST' for siteverify

Related

How can I implement in TYPO 3 server side validation?

I am using TYPO 3 version 6.2.14. In this version I am using Formhandler Plugin to generate a contact form. I have implemented custom code of Google
reCAPTCHA V2 Explicitly render. Now reCAPTCHA code is generated. But it is not performing server side validation. I have also created php file for serverside validation inside fileadmin/templates/fromhandler/serversidevalidation.php
if(isset($_POST['g-recaptcha-response']))
{
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
echo $responseKeys;
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the bot out</h2>';
} else {
echo '<h2>Thanks for posting </h2>';
}
But this simple php file is not including in TypoScript. How can I implement server side validation with formhandler extension. I do not want to use extension because of compatibility issue. Can someone guide me?

How to retrieve respons status from Street View Image Metadata using guzzle

I am using guzzle to call to Street View Image API from my laravel application. I want to be able to retrieve the status code from my request as explained in the end of the docs.
I specifically want to catch the:
{
"status" : "ZERO_RESULTS"
}
here is my Guzzle code from my controller (am including guzzle correctly in namespace). The address in the get call is generating a "Sorry we have no imagery here":
$client = new Client();
$res = $client->get('https://maps.googleapis.com/maps/api/streetview?size=800x600&location=78.648401,14.194336&key=my-API-key&fov=120&heading=90');
$res->getStatusCode();
dd($res->getBody());
BUT. As u can see in the pic the meta-data is empty. When I dd the $res->getStatusCode(); it gives me a 200.
How do I catch the ZERO_RESULT ?
Sir, please note that there are two different endpoints; one for metadata and one for image retrieval. You only used the image retrieval. Here is an example method checking if a given coordinate has an image
private function coordinateHasImage($coordinate)
{
$client = new Client();
$res = $client->get( 'https://maps.googleapis.com/maps/api/streetview/metadata?size=600x300&location=' . $coordinate . '&fov=90&heading=235&pitch=10&key=YOUR_KEY_HERE');
return json_decode($res->getBody()->getContents())->status == "OK";
}

Receiving blank post data with Laravel

I'm developing a simple cart with Laravel 4 and Paypal.
For the IPN Listener I've installed the following package:
- https://github.com/mike182uk/paypal-ipn-listener
I created a route with Route::any() allowing paypal to use any method on the request calling to a function with this simple code:
$listener = new \PayPal\Ipn\Listener;
$verifier = new \PayPal\Ipn\Verifier\CurlVerifier;
$ipnMessage = \PayPal\Ipn\Message::createFromGlobals();
$verifier->setIpnMessage($ipnMessage);
$verifier->setEnvironment('sandbox'); // can either be sandbox or production
$listener->setVerifier($verifier);
$listener->listen(function() use ($listener) {
// on verified IPN (everything is good!)
$resp = $listener->getVerifier()->getVerificationResponse();
$report = $listener->getReport();
$myfile = fopen("ipn.log", "w");
fwrite($myfile, $report);
fclose($myfile);
}, function() use ($listener) {
// on invalid IPN (somethings not right!)
$report = $listener->getReport();
$resp = $listener->getVerifier()->getVerificationResponse();
$myfile = fopen("ipn.log", "w");
fwrite($myfile, $report);
fclose($myfile);
});
When I see the log file Paypal return INVALID, and I see that I dont receive any post data.
But when I use IPN with a single php file with this code from Paypal github I receive all the data.
https://raw.githubusercontent.com/paypal/ipn-code-samples/master/paypal_ipn.php
P.S: I don't get any error, the IPN is sent successfully
The problem was because I had a csrf filter for al routes.
I solved it introducing this route in a group and adding this code to app/filters.php
// CSRF For routes outside "rest" route group.
$firstSegment = Request::segment(1);
if($firstSegment != 'rest')
Route::filter('csrf','post');

mail() on https

I setup a website that uses PHP mail(). I can get it to successfully run if I hit the script on http:// but if I switch to https:// it does not work! I use Godaddy for hosting and have a certificate purchased through them. I am not sure if I need to setup anything in the php.ini file or not. My mailscript looks like this:
$from_respondent_email = "calendar#mydomain.com" ;
$headers_respondent_email = "From: $from_respondent_email";
$subject_respondent_email = "Technical Support Request";
$body_respondent_email = "We received a support ticket from mydomain.com:\n\n";
$body_respondent_email .= "Test block of text";
$send = mail("myname#gmail.com", $subject_respondent_email, $body_respondent_email, $headers_respondent_email);
$to ="myname#gmail.com";
$subject = "Technical Support Request";
$message = "We received a support ticket from mydomain.com:\n\n";
$from = "calendar#mydomain.com";
$headers = "From: $from_respondent_email";
mail($to,$subject,$message,$headers);
Try this. It'll work. I used this in my website and its working :)

Could not instantiate mail function in joomla 2.5.4

I am trying to send mail from my component when the user registers. I tried all three i.e PHPMail, Sendmail and SMTP but none works. I am testing it in localhost (WampServer 2.2) and the Joomla version is 2.5.4. I am not sure this is WampServer problem or Joomla or my own code. This is my code:
function postmail($name, $receiver){
jimport('joomla.mail.helper');
$mailer =& JFactory::getMailer();
$config =& JFactory::getConfig();
$sender = array($config->getValue( 'config.mailfrom'),$config->getValue( 'config.fromname' ) );
$mailer->setSender($sender);
$recipient = $receiver;
$mailer->addRecipient($recipient);
$body = "<body><br><p>";
$body .= "<strong>$name,</strong> ";
$body .= "</p><br></body>";
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$send =& $mailer->Send();
if ( $send != true ) {
//echo 'Error sending email: ' . $send->message;
return false;
} else {
//echo 'Mail sent';
return true;
}
}
It gets the error 'could not instantiate mail function'.
i am sure there are many reasons causing this problem. but to test you can always create a mail server of your own by installing this tool here http://www.toolheap.com/test-mail-server-tool/
you don't have to change anything except that you put localhost as the smtp host in joomla mail settings and then in your webserver's php.ini, add the smtp=localhost. thats it, it should work.
this is just to test whether your code is correct and you are using the correct mail settings in joomla. if this doesn't work then, i am sure the problem is not in your code but in your mail settings.
To understand what the problem is you really need to get the error message.
Change
//echo 'Error sending email: ' . $send->message;
to
echo 'Error sending email:'.$send->get('message');
then run it again. The error that you get should tell us why it isn't instantiating. Let us know what it says so we can help you out.

Resources