首页 > 解决方案 > 如何解决php中的对等证书错误

问题描述

尝试使用file_get_contents()下面的代码片段在 Laravel PHP 中获取文件的内容。该代码在我的本地服务器上运行良好,但当我上传到生产服务器时,我收到以下错误:

ErrorException: file_get_contents(): Peer certificate CN='one46.com' 与预期的 CN='one46.comhttp' 不匹配

$verification_request['face'] = [
   'proof' => base64_encode(file_get_contents($this->faceFile))
];

在代码片段中,$this->faceFile 是对文件 URL 的引用。

标签: phplaravelssl

解决方案


如果通过 HTTP 使用 file_get_contents,您可以通过上下文设置许多连接选项。其中之一是忽略 SSL 问题。尝试这个:

$context = stream_context_create([
  "ssl" => [
    "verify_peer" => FALSE,
    "verify_peer_name" => FALSE,
  ],
  "http" => [
    "ignore_errors" => TRUE,
  ],
]);
file_get_contents($theURL, NULL, $context);

推荐阅读