James Simpson James Simpson - 1 year ago 142
PHP Question

How to get file_get_contents() work with HTTPS?

I'm working on setting up credit card processing and needed to use a workaround for CURL, and the following code worked fine when I was using the test server (which wasn't calling an SSL URL), but now when I am testing it on the working server with HTTPS it doesn't work failing with the error message "failed to open stream".

function send($packet, $url) {
$ctx = stream_context_create(
'header'=>"Content-type: application/x-www-form-urlencoded",
return file_get_contents($url, 0, $ctx);

Answer Source

Try the following script to see if there is an https wrapper available for your php scripts.

$w = stream_get_wrappers();
echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_export($w);

the output should be something like

openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(11) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download