Created
May 13, 2017 08:57
-
-
Save pistol88/2eb4aacce8498058617ebd21adbd8669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static function assertTrueRecaptcha() | |
{ | |
$recaptcha = $_REQUEST['g-recaptcha-response']; | |
$secret = '123123123123123123123'; | |
$url = "https://www.google.com/recaptcha/api/siteverify?secret=".$secret ."&response=".$recaptcha."&remoteip=".$_SERVER['REMOTE_ADDR']; | |
$status = 1; | |
if(!empty($recaptcha)) { | |
$curl = curl_init(); | |
if(!$curl) { | |
$status = 2; | |
} else { | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_TIMEOUT, 10); | |
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16"); | |
$curlData = curl_exec($curl); | |
curl_close($curl); | |
$curlData = json_decode($curlData, true); | |
if($curlData['success']) { | |
$status = 0; | |
} | |
} | |
} | |
if($status === 0) { | |
return true; | |
} else if($status === 1) { | |
throw new \yii\base\ErrorException("Вы не прошли проверку на спам."); | |
} else if($status === 2) { | |
throw new \yii\base\ErrorException("Системная ошибка проверки на каптчу."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment