Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用自签名证书在MAMP中获取文件内容失败_Php_Ssl_Svg_File Get Contents_Self Signed Certificate - Fatal编程技术网

Php 使用自签名证书在MAMP中获取文件内容失败

Php 使用自签名证书在MAMP中获取文件内容失败,php,ssl,svg,file-get-contents,self-signed-certificate,Php,Ssl,Svg,File Get Contents,Self Signed Certificate,我正在使用file_get_contents()在我的站点中包含svg文件。通常这在http上可以正常工作,但我将此站点设置为在本地使用https。当我这样做时,我会出现以下错误: Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate ver

我正在使用file_get_contents()在我的站点中包含svg文件。通常这在http上可以正常工作,但我将此站点设置为在本地使用https。当我这样做时,我会出现以下错误:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed on line 226

Warning: file_get_contents(): Failed to enable crypto on line 226

据我所知,这是因为证书是自签名的。我找到了一个本地解决方案,可以禁用对文件get内容的SSL检查。我用cURL找到了类似的东西。然而,这似乎是一个安全漏洞。有没有一种方法可以在不禁用文件\u get\u contents或cURL中的SSL检查的情况下实现这一点

您需要允许使用自签名证书。为此,您需要定义一个自定义流上下文

例如:

file_get_contents(
    'https://self-signed.badssl.com/',
    false,
    stream_context_create([
        'ssl' => [
            'allow_self_signed'=> true
        ]
    ])
);

您还可以尝试升级MAMP的版本。这对我有用。在MacOS Catalina上运行MAMP时,我在MAMP上落后了两个版本,遇到了一个类似的SSL错误,在浪费大量时间阅读各种Stackoverlow线程寻找解决方案后,通过升级MAMP最终解决了这个问题。

您能回答作者的问题吗“有没有一种方法可以在不禁用文件\u get\u contents中的SSL检查的情况下实现此功能?”更新了答案,现在它只允许使用自签名证书。另一种方法是,OP不应使用自签名证书。