广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >PHP报错:Warning: file_get_contents(): Failed to enable crypto
  • 784
分享到

PHP报错:Warning: file_get_contents(): Failed to enable crypto

php服务器开发语言 2023-09-02 17:09:02 784人浏览 薄情痞子
摘要

一、说明二、原因三、解决1、Linux服务器配置https ssl证书;2、curl_ 请求获取内容(见下面的方法curlGet())3、使用file_get_contents()函数跳过

一、说明

  • file_get_contents()读取 https 内容时报错

二、原因

  • 本地服务没有配置ssl证书,不能获取到Https的路径的内容

三、解决

1、linux服务器配置https ssl证书;

  • Linux服务器配置https ssl证书;

2、curl_ 请求获取内容(见下面的方法curlGet())

        function curlGet($url)    {        $ch = curl_init($url);        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (windows NT 6.1; WOW64) AppleWEBKit/537.36 (Khtml, like Gecko) Chrome/55.0.2883.87 Safari/537.36');        curl_setopt($ch, CURLOPT_TIMEOUT, 30);        $content = curl_exec($ch);        curl_close($ch);        return ($content);    }

3、使用file_get_contents()函数跳过https验证

        $streamOpts = [            'ssl' => [                'verify_peer' => false,                'verify_peer_name' => false            ]        ];        $html = file_get_contents($pageUrl, false, stream_context_create($streamOpts));

来源地址:https://blog.csdn.net/qq_36025814/article/details/126919045

--结束END--

本文标题: PHP报错:Warning: file_get_contents(): Failed to enable crypto

本文链接: https://www.lsjlt.com/news/391144.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作