Я использую recaptcha 2 и получаю эту странную ошибку: Примечание: file_get_contents (): Content-type не указан, если application / x-www-form-urlencoded in ... в строке 38.
код:
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<?php
$page = "contact";
include("includes/navbar.php");
echo '<div id = "wrapper">';
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '6LfJnWQUAAAAANMRQApsnetVjggDqnn4hx7Ltbyz',
'response' => $_POST["g-recaptcha-response"]
);
$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) {
echo "<h1>You did not prove you are human.</h1><h2> Please go back and complete the form!</h2>";
exit();
}
else if ($captcha_success->success==true) {
more code here to execute if captcha successfull
строка 38, которая вызывает сообщение об ошибке:
$verify = file_get_contents($url, false, $context);
Сообщение об ошибке появляется независимо от того, отмечен ли флажок робота. Если флажок не установлен, появляется сообщение «Вы не доказали, что вы человек», а если флажок робота отмечен, код обрабатывается правильно, хотя сообщение об ошибке все равно появляется.
Как удалить сообщение об ошибке? На сайте есть SSL-сертификат, поэтому я попытался изменить:
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
к:
$options = array(
'https' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
и это удаляет сообщение об ошибке, но затем появляется сообщение «Вы не доказали, что вы человек», даже если флажок робота установлен.
Я в тупике.
С Уважением
Tog






Я думаю, что в ваших опциях отсутствует параметр, попробуйте что-то вроде этого:
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data),
'header' => 'Content-Type: application/x-www-form-urlencoded'
)
);
Да, я исправил это с помощью:
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<?php
$page = "contact";
include("includes/navbar.php");
echo '<div id = "wrapper">';
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => '6LfJnWQUAAAAANMRQApsnetVjggDqnn4hx7Ltbyz',
'response' => $_POST["g-recaptcha-response"]
);
$query = http_build_query($data);
$options = 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' => $query
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<h1>You did not prove you are human.</h1><h2> Please go back and complete the form!</h2>";
exit();
}
else if ($captcha_success->success==true) {
more code here to execute if captcha successfull