8

我想在 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 配置吗?

4

2 回答 2

17

检查这个 - 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; ?>
于 2015-09-28T10:44:15.760 回答
13

请参阅通过 https 使用 php 加载外部 xml 文件时出错: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 上下文选项stream_context_create

于 2015-09-28T10:44:04.413 回答