-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisRecaptchaValid.php
More file actions
34 lines (32 loc) · 943 Bytes
/
isRecaptchaValid.php
File metadata and controls
34 lines (32 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// fonction de vérification du captcha
function isRecaptchaValid($code, $ip = null)
{
if(empty($code)) {
return false;
}
$params = [
'secret' => '6Lc9SS4UAAAAAKD1bH_Yz3kxQfv3KOrM_8MYs7oK',
'response' => $code
];
if($ip){
$params['remoteip'] = $ip;
}
$url = "https://www.google.com/recaptcha/api/siteverify?" . http_build_query($params);
if(function_exists('curl_version')){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
}else{
$response = file_get_contents($url);
}
if(empty($response) || is_null($response)){
return false;
}
$json = json_decode($response);
return $json->success;
}
?>