<?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/