Fopen接受自签名证书 [英] Fopen accept self signed certificate
问题描述
我想在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);