2017-11-29 9 views
0
<?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]; 
?> 

내 PHP가 admin 패널의 서버 상태에서 통계를 얻을 수 있도록 localhost가 항상 https로 간다. 즉, SSL이 활성화되어 PHP가 내용을 가져올 수 없다는 것을 의미한다. localhost에서는 유효하지 않습니다.localhost에서 자체 서명 된 PHP를 허용 하시겠습니까? (SSL을 사용 안함?)

file_get_contents를 수행 할 때 어떻게 비활성화합니까?

+3

왜 서버가 인증서를 신뢰하지 않습니까? https://unix.stackexchange.com/questions/90450/adding-a-self-signed-certificate-to-the-rusted-list – ceejayoz

+0

첫 번째 줄은'$ content' 대신'$ context'라고되어 있습니까? 당신은 또한'file_get_contents' 호출에 그것을 전달하지 않을 것입니다. 또는 자동으로 적용되는 컨텍스트로'stream_context_set_default'를 호출 할 수도 있습니다. – iainn

+0

@iainn 어떻게하면 좋을까요? 내가 잘못 나온 곳을 찾아내는 데 도움이 될만한 답변을 게시 할 수 있습니까? – rakupu

답변

1

당신은 당신이 file_get_contents 전화에 자신이 만든 스트림 컨텍스트 전달해야 내가 여기 verify_peer_name 옵션에 추가 한

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

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

을,하지만 당신은 그것을 필요로하지 않을 수 있습니다.

+0

GENIUS! 감사합니다. – rakupu