简体   繁体   English

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

[英]recaptcha error; Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in

I am using recaptcha 2 and getting this weird error: Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in... on line 38.我正在使用 recaptcha 2 并收到这个奇怪的错误:注意:file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in... 在第 38 行。

the code is:代码是:

<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

line 38 that triggers the error message is:触发错误消息的第 38 行是:

$verify = file_get_contents($url, false, $context);

The error message appears whether or not the robot box has been ticked.无论是否勾选了机器人框,都会出现错误消息。 If the box has not been ticked, the "You did not prove you are human" message appears and if the robot box has been ticked the code is correctly processed, although the error message still appears.如果未勾选该框,则会出现“你没有证明你是人类”消息,如果已勾选机器人框,则代码将得到正确处理,但仍会出现错误消息。

How can I remove the error message?如何删除错误消息? The site has an SSL certificate so I tried changing:该站点有一个 SSL 证书,所以我尝试更改:

$options = array(
            'http' => array (
                'method' => 'POST',
                'content' => http_build_query($data)
            )
        );

to:到:

$options = array(
            'https' => array (
                'method' => 'POST',
                'content' => http_build_query($data)
            )
        );

and that removes the error message, but then the "You did not prove you are human" message appears, even if the robot box is checked.并且删除了错误消息,但是即使选中了机器人框,也会出现“你没有证明你是人”的消息。

I am stumped.我很难过。

Regards问候

Tog托格

I think there is a parameter missing inside your options, try something like this: 我认为您的选项中缺少一个参数,请尝试如下操作:

$options = array(
    'http' => array (
                'method' => 'POST',
                'content' => http_build_query($data),
                'header' => 'Content-Type: application/x-www-form-urlencoded'
            )
        );

Yes, I fixed it with: 是的,我通过以下方式修复了该问题:

<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
$secretKey  = '------------Your S-Key---------------';
    $token      = $_POST["g-token"];
    $ip         = $_SERVER['REMOTE_ADDR'];
   
    /* ======================= POST METHOD =====================*/ 
    $url = "https://www.google.com/recaptcha/api/siteverify?";
    $data = array('secret' => $secretKey, 'response' => $token, 'remoteip'=> $ip);
 
    // use key 'http' even if you send the request to https://...
    $options = array('http' => array(
        'method'  => 'POST',
        'content' => http_build_query($data),
        'header' => 'Content-Type: application/x-www-form-urlencoded'
    ));
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $response = json_decode($result);
    if($response->success)
    {
        

             echo '<center><h1>Validation Success!</h1></center>';
    }
    else
    {
        echo '<center><h1>Captcha Validation Failed..!</h1></center>';
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 file_get_contents():假设应用程序/x-www-form-urlencoded 未指定内容类型 - file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded file_get_contents():假设application / x-www-form-urlencoded with imgur API,未指定Content-type - file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded with imgur API PHP - 假设应用程序/x-www-form-urlencoded 未指定内容类型 - PHP - Content-type not specified assuming application/x-www-form-urlencoded 的file_get_contents( &#39;PHP://输入&#39;); 与application / x-www-form-urlencoded; - file_get_contents('php://input'); with application/x-www-form-urlencoded; 如何使用内容类型从 webhook 获取数据:application/x-www-form-urlencoded;charset=UTF-8? - How to get data from webhook with content-type: application/x-www-form-urlencoded;charset=UTF-8? 使用Content-Type = application / x-www-form-urlencoded发送POST请求时,POST值为空 - POST value is empty when Sending POST request with Content-Type = application/x-www-form-urlencoded 如何通过在laravel中传递参数来获得内容类型application/x-www-form-urlencoded的响应 - How to get response of content type application/x-www-form-urlencoded by passing parameters in laravel PHP curl将Content-Type更改为application / x-www-form-urlencoded。 不应该这样做 - PHP curl changes the Content-Type to application/x-www-form-urlencoded. Shouldn't do that 如何使用内容类型为“ application / x-www-form-urlencoded”的PHP curl发送原始JSON? - How can I send a raw JSON using PHP curl with the content type “application/x-www-form-urlencoded”? 使用标题应用程序/ x-www-form-urlencoded进行卷曲发布 - curl posting with header application/x-www-form-urlencoded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM