【问题标题】:Fopen accept self signed certificatefopen 接受自签名证书
【发布时间】:2015-12-25 12:58:45
【问题描述】:

我想在 php 变量中获取我的页面在 https 中的结果,但 fopen 函数返回 false;

我认为这个错误可能是自签名的 ssl 证书的产物

fopen("https://192.168.1.1:8443", "rb"))

警告:fopen():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

是接受所有证书的php ssl配置吗?

【问题讨论】:

    标签: php fopen php-5.6 nuxeo


    【解决方案1】:

    检查这个 - http://php.net/manual/en/function.stream-context-create.php

    <?php
    $opts=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );  
    
    $response = fopen("https://192.168.1.1:8443", 'rb', false, stream_context_create($opts));
    
    echo $response; ?>
    

    【讨论】:

    • 应该是$response = fopen("https://192.168.1.1:8443", 'rb', false, stream_context_create($opts));你跳过了1个参数
    【解决方案2】:

    Error when loading external xml file with php via https : SSL3_GET_SERVER_CERTIFICATE

    导出您的 PEM 编码的自签名证书并将其附加到 ca-bundle.crt(或者如果还没有 ca-bundle.crt,只需重命名您的导出文件)

    然后使用

    $context = stream_context_create(array('ssl'=>array(
        'verify_peer' => true,
        'cafile' => '/path/to/ca-bundle.crt'
    )));
    $fd = fopen("https://192.168.1.1:8443", "rb", false, $context);
    

    SSL context optionsstream_context_create

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-18
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多