Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
system
/
plugins
/
jQueryUI
:
recaptcha.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php class reCaptcha{ const MISSING_INPUT_SECRET="missing-input-secret"; const INVALID_INPUT_SECRET="missing-input-secret"; const MISSING_INPUT_RESPONSE="missing-input-response"; const INVALID_INPUT_RESPONSE="invalid-input-response"; private $secret; private $error_code; function __construct($secret){ $this->secret=$secret; } function CheckHumanFromPost(){ if(!empty($_POST['g-recaptcha-response'])){ return $this->IsHuman($_POST['g-recaptcha-response']); }else{ $this->error_code=self::MISSING_INPUT_RESPONSE; return false; } } function IsHuman($g_recaptcha_response){ $ch = curl_init('https://www.google.com/recaptcha/api/siteverify'); //$ch = curl_init('http://192.168.10.71/Projects/gsreport/api/api.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "secret=".$this->secret."&response=$g_recaptcha_response&remoteip=".$_SERVER['REMOTE_ADDR']); $result = curl_exec($ch); curl_close ($ch); if(!empty($result)){ $response=json_decode($result); if(is_object($response)){ if($response->success){ return true; }else{ $er="error-codes"; $errors=&$response->$er; if(!empty($errors[0])){ $this->error_code=$errors[0]; } } }else{ $this->error_code="unknown"; } } return false; } function IsErrorByErrorCode($errorcode){ if($this->error_code==$errorcode){ return true; } return false; } function GetErrorCode(){ return $this->error_code; } }