允许在localhost上使用自签名PHP? (禁用SSL?)

时间:2017-11-29 13:57:09

标签: 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可以从管理面板的服务器状态获取一些统计信息,但localhost总是转到https,这意味着由于启用了SSL而无法在本地主机上生效,因此PHP无法获取内容。 / p>

我在执行file_get_contents时如何禁用此功能?

1 个答案:

答案 0 :(得分:2)

您需要将您创建的流上下文传递给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选项,但您可能不需要它。