Created
November 26, 2019 20:26
-
-
Save mindpalette/edd2c7f72a3295583d8441aa9d8e8655 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// file_get_contents wrapper to allow self-signed certs for local dev domains | |
function contextual_file_get_contents( $url ) { | |
$server_name = (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : ''; | |
$localext = '.local'; | |
if ($server_name && substr($server_name, -strlen($localext)) === $localext) { | |
$context = stream_context_create(['ssl' => [ | |
'verify_peer_name'=>false, | |
'verify_peer'=>false, | |
'allow_self_signed'=> true | |
] ]); | |
return file_get_contents($url, false, $context); | |
} else return file_get_contents($url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround for SSL errors when using file_get_contents on MAMP local environment (file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed). Assumes local dev domains have ".local" extension on line 6 (change as needed, or use full dev domain name)