<?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可以从服务器状态中获取一些管理面板的统计信息,但是localhost总是转到https,这意味着PHP无法获取内容,因为SSL已启用且在localhost上无效。
在执行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
选项,但是您可能不需要它。