Reputation: 15484
i need to read the content of a web page using php with this simple command:
$pagina='https://graph.facebook.com/me?access_token=' . $cookie['access_token'];
$user = json_decode(file_get_contents($pagina));
As you can see the protocol is https. When i execute this commands i always get:
[function.file-get-contents]: failed to open stream:
In other answer in stackoverflow some user suggest to use this code:
$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_dump($w);
In order to know if my server have https wrapper, and the result was No.
So, any idea of how can i retrive this https page using php? maybe with CURL any example code? Thanks a lot!
Upvotes: 2
Views: 578
Reputation: 2939
Https sites work with curl
<?php
$url = "https://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Upvotes: 2