【发布时间】:2019-02-19 10:25:10
【问题描述】:
我昨天才注意到,我的 reCAPTCHA 有问题,去年还好。
这是我的代码:
public function message(Request $request) {
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '6LcwXi8UAAAAAE9zNCVfqwDOIWNazNgdK-0wQv9L',
'response' => $_POST["g-recaptcha-response"]
);
//For debug purpose (remove comments)
//dd($request->all());
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
return redirect('/')->with('success', 'You are a bot! Go away!');;
} else if ($captcha_success->success==true) {
$content = array (
'http' => array (
'header' => "Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($query)."\r\n".
"User-Agent:MyAgent/1.0\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
当我提交联系表格时,它给了我这个错误:
PagesController.php 第 37 行中的 ErrorException:
file_get_contents(): 内容类型未指定假设 应用程序/x-www-form-urlencoded
第 37 行是:
$verify = file_get_contents($url, false, $context);
【问题讨论】:
标签: recaptcha file-get-contents