【问题标题】:Issue : Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in php [duplicate]问题:警告:file_get_contents(): https:// wrapper 在服务器配置中被 php 中的 allow_url_fopen=0 禁用 [重复]
【发布时间】:2018-07-23 11:19:43
【问题描述】:

实际上,我正在开发 Core PHP,现在我正在创建带有邮件功能的 google recaptcha 联系我们页面,所以当我应用 google recaptcha 代码时会显示如下问题:

警告:file_get_contents(): https:// 包装器在 通过 allow_url_fopen=0 配置服务器

请帮助任何人。

我的代码是:

<?php
  ini_set('display_errors',1);  error_reporting(E_ALL);
  if(isset($_POST['submit'])){
      $userIP = $_SERVER["REMOTE_ADDR"];
      $recaptchaResponse = $_POST['g-recaptcha-response'];
      $secretKey = 'xxx';
      $request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secretKey}&response={$recaptchaResponse}&remoteip={$userIP}");

      if(!strstr($request, "true")){
          echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem with the Captcha, you lied to us! you are a robot! or you just didnt click it :)</div>';
      }
      else{
          // echo "WORKS";
        if(isset($_POST['submit'])) 
        {

        $message=
        'Full Name: '.$_POST['fullname'].'<br />
        Subject:    '.$_POST['subject'].'<br />
        Phone:  '.$_POST['phone'].'<br />
        Email:  '.$_POST['emailid'].'<br />
        Comments:   '.$_POST['comments'].'
        ';
            require "PHPMailer-master/class.phpmailer.php"; //include phpmailer class

            // Instantiate Class  
            $mail = new PHPMailer();  

            // Set up SMTP  
            $mail->IsSMTP();                // Sets up a SMTP connection  
            $mail->SMTPAuth = true;         // Connection with the SMTP does require authorization    
            $mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
            $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
            $mail->Port = 465;  //Gmail SMTP port
            $mail->Encoding = '7bit';

            // Authentication  
            $mail->Username   = $senderEmail; // Your full Gmail address
            $mail->Password   = $senderPassword; // Your Gmail password

            // Compose
            $mail->SetFrom($_POST['emailid'], $_POST['fullname']);
            $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
            $mail->Subject = "New Contact Form Enquiry";      // Subject (which isn't required)  
            $mail->MsgHTML($message);

            // Send To  
            $mail->AddAddress($receiverEmail, $receiverName); // Where to send it - Recipient
            $result = $mail->Send();        // Send!  
            $message = $result ? '<div class="alert alert-success" role="alert"><strong>Success!</strong>Message Sent Successfully!</div>' : '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem delivering the message.</div>';  

            unset($mail);

        }
      }
  }


?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHPMailer Contact Form</title>
       <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src='https://www.google.com/recaptcha/api.js'></script>
  </head>
  <body>
    <div class="contactform">
    <div class="panel panel-default">
      <div class="panel-heading">
      <h3 class="panel-title"><a href="">Contact Form</a></h3>
      </div>
      <div class="panel-body">
      <form name="form1" id="form1" action="" method="post">
          <fieldset>
            <input type="text" class="form-control" name="fullname" placeholder="Full Name" />
            <br />
            <input type="text" class="form-control" name="subject" placeholder="Subject" />
            <br />
            <input type="text" class="form-control" name="phone" placeholder="Phone" />
            <br />
            <input type="email" class="form-control" name="emailid" placeholder="Email" />
            <br />
            <textarea rows="4" class="form-control" cols="20" name="comments" placeholder="Comments"></textarea>
            <br />
            <div class="g-recaptcha" data-sitekey="6Ldgy2QUAAAAAPRkDWHgLJ81rRVdca0V1Qq2t8mA12"></div>
            <input type="submit" class="btn  btn-lg btn-success button"name="submit" value="Send Message" />

          </fieldset>
      </form>
      <p><?php if(!empty($message)) echo $message; ?></p>
      </div>
  </div>
  </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  </body>
</html>

【问题讨论】:

标签: php html


【解决方案1】:

这个信息很清楚:

file_get_contents() 不允许使用https:// 的方案打开文件。

这是因为您的 PHP 运行时配置 allow_url_fopen 设置为 0

来自Runtime configuration manual:“此选项启用可识别 URL 的 fopen 包装器,从而能够访问 URL 对象(如文件)。

编辑您的网络服务器的php.ini 文件并将allow_url_fopen 更改为1,重新启动您的服务器,您应该能够打开远程文件。

【讨论】:

  • 如果您无法编辑php.ini,请尝试使用 curl。
猜你喜欢
  • 2017-11-24
  • 2019-03-06
  • 1970-01-01
  • 2014-06-10
  • 2016-08-25
  • 2018-01-22
  • 1970-01-01
相关资源
最近更新 更多