What is wrong with this bit of code. Whether I tick the reCAPTCHA or not, it goes onto the else clause.
<?php // This is added for Google Captcha $url = 'https://www.google.com/recaptcha/api/siteverify'; $privatekey = '6LdBjyATAAAAABZe1O-DKBEQnOIzanoVLGEvsvyu'; $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']); $data = json_decode($response); if($response.success==false){ echo "<h2>Spam Spam go away</h2><p>And if you're not spam, we apologise. Please go back and tick the reCAPTCHA box.</p><p>Thank you</p>"; die(); } else { // do loads of clever stuff }
var_dump($response);That's the javascript way of getting array/object values; in PHP, the period is for concatenation. If$responseis an array, it would be$response['success'], if it's an object, it's$response->success.