gpt4 book ai didi

php - 重新验证错误;通知 : file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in

转载 作者:行者123 更新时间:2023-12-05 04:05:21 25 4
gpt4 key购买 nike

我正在使用 recaptcha 2 并收到这个奇怪的错误:注意:file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in ... on line 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)
)
);

这会删除错误消息,但随后会出现“你没有证明你是人类”消息,即使选中了机器人框也是如此。

我被难住了。

问候

最佳答案

是的,我修复了它:

<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

关于php - 重新验证错误;通知 : file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51379128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com