php空间不支持socket但支持curl时recaptcha的用法_php技巧
程序员文章站
2022-06-09 11:47:10
...
1.修改recaptchalib.php中的两个方法
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$response = '';
$url = $host.$path;
$post_data = $req;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 我们在POST数据哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
//echo $output;
$response = $output;
return $response;
}
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
if ($privkey == null || $privkey == '') {
die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
}
if ($remoteip == null || $remoteip == '') {
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
}
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $privkey,
'remoteip' => $remoteip,
'challenge' => $challenge,
'response' => $response
) + $extra_params
);
$answers = explode ("\n", $response [1]);
$recaptcha_response = new ReCaptchaResponse();
$pos = strpos($response, 'true');
if ($pos === false) {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $response;
} else {
$recaptcha_response->is_valid = true;
}
return $recaptcha_response;
}
2.demo.php
复制代码 代码如下:
function _recaptcha_http_post($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$response = '';
$url = $host.$path;
$post_data = $req;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 我们在POST数据哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
//echo $output;
$response = $output;
return $response;
}
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
if ($privkey == null || $privkey == '') {
die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
}
if ($remoteip == null || $remoteip == '') {
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
}
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $privkey,
'remoteip' => $remoteip,
'challenge' => $challenge,
'response' => $response
) + $extra_params
);
$answers = explode ("\n", $response [1]);
$recaptcha_response = new ReCaptchaResponse();
$pos = strpos($response, 'true');
if ($pos === false) {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $response;
} else {
$recaptcha_response->is_valid = true;
}
return $recaptcha_response;
}
2.demo.php
复制代码 代码如下:
上一篇: Cookie和Session的区别
下一篇: Windows访问OEM乱码解决
推荐阅读
-
php空间不支持socket但支持curl时recaptcha的用法
-
php空间不支持socket但支持curl时recaptcha的用法_PHP教程
-
php空间不支持socket但支持curl时recaptcha的用法
-
php空间不支持socket但支持curl时recaptcha的用法_php技巧
-
php空间不支持socket但支持curl时recaptcha的用法
-
php空间不支持socket但支持curl时recaptcha的用法_PHP
-
captcha php空间不支持socket但支持curl时recaptcha的用法
-
php空间不支持socket但支持curl时recaptcha的用法_PHP教程