php - 允许在本地主机上自签名 PHP? (禁用 SSL?)

标签 php apache .htaccess ssl https

<?php
$content = [ 'http' => [ 'method' => 'GET' ], 'ssl' => [ 'verify_peer' => false, 'allow_self_signed'=> true ] ];
$url = 'http://localhost/server-status';
$content = file_get_contents($url);
$first_step = explode( 'Current' , $content );
$second_step = explode("</dl>" , $first_step[1] );

echo $second_step[0];
?>

我正在尝试禁用 SSL,以便我的 PHP 可以从管理面板的服务器状态获取一些统计信息,但本地主机始终转到 https,这意味着 PHP 无法获取内容,因为 SSL 已启用且在本地主机上无效。

如何在执行 file_get_contents 时禁用它?

最佳答案

您需要将创建的流上下文传递给 file_get_contents 调用:

$context = stream_context_create(['ssl' => [ 'verify_peer_name' => false, 'verify_peer' => false, 'allow_self_signed'=> true ] ]);

$content = file_get_contents('https://localhost/', false, $context);

我在此处添加了 verify_peer_name 选项,但您可能不需要它。

关于php - 允许在本地主机上自签名 PHP? (禁用 SSL?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47554516/

相关文章:

apache - 大规模 URL 更改

.htaccess - 如何给一个子页面它自己的域名?

php - htaccess 使用 https 将 php 重定向到 html

apache - htaccess 重写规则,不带 R 标志创建外部重定向

php - 获取最终重定向 URL

php - 通过 Javascript 中的 xmlHttpRequest 将查询字符串值发送到另一个 php 页面时,查询字符串值被 chop 吗?

php - 验证多个复选框 laravel 5.2

php - IOS中的推送通知-握手失败

php - 没有什么会取消设置 X-Frame-Options (Apache, PHP 5.3)

php - 用 mod_rewrite 或像 PHP 这样的语言处理友好/干净/漂亮的 URL 更好吗?