rakupu rakupu - 3 months ago 39
Apache Configuration Question

Allow self-signed PHP on localhost? (Disable SSL?)

$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];

I am trying to disable SSL so my PHP can get some stats from server-status for the admin panel, but localhost always goes to https which means PHP cannot get the content due to SSL being enabled and not valid on localhost.

How do I disable this when I am doing file_get_contents?

Answer Source

You need to pass the stream context you've created to the file_get_contents call:

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

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

I've added in the verify_peer_name option here, but you might not need it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download