captcha - Google recaptcha and PHP -
i trying troubleshoot form using google recaptcha version 1.0 - when form gets submitted g-recaptcha-response filled means google happy real person recaptcharesponse empty meaning form not submit cannot sure real person.
when form submitted value in $_post:
[g-recaptcha-response] => 03ahj_vuvki7ovsl6bzug1nn5wpok4huilmhafmml1rmeiwwzn-tij8iryae01z-rjzaatfbkp2itfc2snrtv3v7cg7yosospqxumsuldghcqwg7cedscxlsuaab6jontoqypti0vp4n6sfupg0gfnjmkxjpnefennvscimsvtikubhfy18byzxtarxcqjb_r_ehcnil0zm5hhpiejufajyqgivz1grqkr_bzhlkzvckvqkrw9zl-rvrgthufqi_ifjrnl5ze5ev1vwrezfx9j8aoq1gkyw6cjk8wysrp9ax816ifnyyaptv_nim6qbpm3nftejlz0ft0fu7kd5mqofllqsarvopsdt-w2hrl4eknbiea-yrdwpu9-8-lx3wtzy6kvdm_9cb_8i1tjkoamu70mxc0yl5i9rf0nlus_hagwcizfdw9v5ptiiyed9hpiw3h4nzpzbkac3faruqznkftempo0telilq [submit] => ) and content of recaptcharesponse:
recaptcharesponse object ( [success] => [errorcodes] => ) here code using validate response - fails on !$response->success makes sense success empty why empty when g-recaptcha-response populated?
$secret= "my_secret"; require_once('recaptchalib.php'); $recaptcha = new recaptcha($secret); if ($_post["g-recaptcha-response"]) { $response = $recaptcha->verifyresponse( $_server["remote_addr"], $_post["g-recaptcha-response"] ); print_r($response); print $response->success; print $response->error-codes; if ($response == null) { $error_message='<p>please validate captcha response 1</p>'; $error=1; } elseif (!$response->success){ $error_message='<p>please validate captcha response 2</p>'; $error=1; } } else { $error_message='<p>please validate captcha response 3</p>'; $error=1; }
for responses that, use var_dump() instead of print_r(), latter prints false , null whitespace.
print_r($response); -> recaptcharesponse object ( [success] => [errorcodes] => ) var_dump($response); -> object(recaptcharesponse)#1 (2) { ["success"]=> bool(false) ["errorcodes"]=> null }
Comments
Post a Comment