一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - php空間不支持socket但支持curl時recaptcha的用法

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

2019-12-16 14:23PHP教程網 PHP教程

php空間不支持socket但支持curl時recaptcha的用法,需要的朋友可以參考下。

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 <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>"); 

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 

復制代碼代碼如下:


<html> 
<body> 
<form action="" method="post"> 
<?php 
require_once('recaptchalib.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 = recaptcha_check_answer ($privatekey, 
$_SERVER["REMOTE_ADDR"], 
$_POST["recaptcha_challenge_field"], 
$_POST["recaptcha_response_field"]); 
if ($resp->is_valid) { 
echo "You got it!"; 
} else { 
# set the error code so that we can display it 
$error = $resp->error; 
echo $error; 
//echo $_POST["recaptcha_challenge_field"]; 
//echo $_POST["recaptcha_response_field"]; 


echo recaptcha_get_html($publickey, $error); 
?> 
<br/> 
<input type="submit" value="submit" /> 
</form> 
</body> 
</html> 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲 日韩经典 中文字幕 | 日本无遮挡吸乳视频看看 | 日本68xxxxxxxxx59 日本 视频 在线 | 风间由美一区二区播放合集 | 经典WC女厕所里TV | 国产9191精品免费观看 | 国产成人亚洲精品91专区手机 | 午夜办公室 | 果冻传媒和91制片厂网站软件 | 99久久精品国语对白 | 亚洲国产在线观看免费视频 | 美女操批 | gogort99人体专业网站 | 午夜精品区 | 成人免费影院 | 免费国产在线视频 | 99视频在线免费 | 天天翘 | 日韩一级精品视频在线观看 | 精品淑女少妇AV久久免费 | 青草精品| 国产精品一级片 | 日本老妇乱子伦中文视频 | 俄罗斯引擎首页进入 | 亚洲人成网站在线观看妞妞网 | 北岛玲在线播放 | www.99热| 日韩无遮挡大尺度啪啪影片 | 亚洲图片综合区 | 国产精品猎奇系列在线观看 | 欧美高清在线精品一区 | 午夜黄视频| 亚洲午夜精品久久久久久抢 | 国产嫩草视频 | 国产高清好大好夹受不了了 | 美女的隐私无遮挡的网页 | 国产好痛疼轻点好爽的视频 | 亚洲天堂精品在线 | 色老板在线观看 | 日本一片免费观看高清完整 | 亚洲干综合 |