首頁 >後端開發 >php教程 >captcha php空間不支援socket但支援curl時recaptcha的用法

captcha php空間不支援socket但支援curl時recaptcha的用法

WBOY
WBOY原創
2016-07-29 08:47:141193瀏覽

1.修改recaptchalib.php中的兩個方法

複製程式碼 程式碼如下:


function _recaptcha_http_post($host, $path, $data, $port = 800) {$m. data);
$response = '';
$url = $host.$path;
$post_data = $req;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_URL, $url); ? $ch, CURLOPT_RETURNTRANSFER, 1);
// 我們在POST資料哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的變數加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
$ //echo $output;
$response = $output;
return $response;
}
function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array(ptra_param)($ priv) == 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($challenge) == 0 || $response == null || strlen($response)|| == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response>error = 'incorrect-ccha-solect-cide; aptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
array (
'privatekey' => $privkey,
'remoteip' => $remoteip,
'challenge' => $ponlenge, s
) + $extra_params
);
$answers = explode ("n", $response [1]);
$recaptcha_response = new ReCaptchaResponse();
$pos = strpos($response); ($pos === false) {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $response;
} else {
$recaptcha_response->is_valid = is


2.demo.php



複製程式碼

程式碼如下:



// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "你的公用key ---自己去http://www.google. com/recaptcha申請";

$privatekey = "你的私有key ---自己去http://www.google.com/recaptcha申請"; # the response from reCAPTCHA $resp = null; # the error code from reCAPTCHA, if any $error = null;

# was there a reCAPTCHA response?

if ($_POST["recaptcha_response_field"]) {
$resp = reccha_private,RE,Fvpriv.
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
echo "You got it!";
} 那we can display it
$error = $resp->error;
echo $error;
//echo $_POST["recaptcha_challenge_field"];
//echo $_POST["reccha_response_pcha_responx"]; ($publickey, $error);
?>








以上就介紹了captcha php空間不支援socket但支援curl時recaptcha的用法,包括了captcha方面的內容,希望對PHP教程有興趣的朋友有所幫助。


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn