代码之家  ›  专栏  ›  技术社区  ›  Marcos Felipe

文件\u获取\u内容,不返回

  •  0
  • Marcos Felipe  · 技术社区  · 7 年前

    这是我的密码:

    if ($_REQUEST["send"] == 1){
    
        // access
        $secretKey = 'my_key';
        $captcha = $_POST['g-recaptcha-response'];
        $ip = $_SERVER['REMOTE_ADDR'];
    
        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
    
        echo ($responseKeys);exit;
    
        if(intval($responseKeys["success"]) !== 1) {
            $message = 'Invalid reCAPTCHA';
        } else {
    
            $msg = 'content';
    
            send_mail('send_to',"Subject",$msg);
            header("location:index.php?send=1");exit;
    
        }
    
    } 
    

    我的变量响应返回空。

    https://www.google.com/recaptcha/api/siteverify ? 手动插入变量,看起来效果不错。

    谢谢

    2 回复  |  直到 7 年前
        1
  •  0
  •   Maxim    7 年前

    他们的API正在等待POST请求。您的代码发送获取请求。

    看到答案了吗 How to post data in PHP using file_get_contents?

        2
  •  0
  •   Marcos Felipe    7 年前

    我的包装被禁用,这就是我无法访问URL并获取返回的原因。

        $url = "https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip;
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            echo curl_error($ch);
            echo "\n<br />";
            $response = '';
        } else {
            curl_close($ch);
        }
    
        if (!is_string($response) || !strlen($response)) {
            echo "Failed to get contents.";
            $contents = '';
        }
    
        $responseKeys = json_decode($response,true);
    
    推荐文章