Fopen接受自签名证书 [英] Fopen accept self signed certificate

查看:100
本文介绍了Fopen接受自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i would like to get the result of my page in https in a php variable but the fopen fonction return false;

我认为此错误可能是由自签名的ssl证书引起的

i think this error can be product by the ssl certifacte which is self signed

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

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

Warning: fopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

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

Is it a php ssl configuration to accept all certificate ?

推荐答案

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

Export your self-signed certificate PEM-encoded and append it to ca-bundle.crt (or if there is no ca-bundle.crt yet, just rename your export file)

然后使用

$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上下文选项 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆