I'm attempting to read a Facebook page using https protocol with Fopen, and while I can read the page it is encrypted gibberish. Hopefully someone has figured this out. Please note this is a freely available page that works in any modern browser.
What I've done so far:
Enabled openssl in the php extensions
Faked the browser id to make facebook respond
I've added some SSL info I found on the web to the context options but it is not working. I'm guessing I have to generate and store a certificate but have no idea how to do that. I also have no idea what the capath should be in wamp.
Code Follows
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n".
"Accept-language: en-US,en;q=0.5\r\n" .
"Accept-Encoding: gzip, deflate\r\n".
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
,
'ssl'=>array('verify_peer'=>true, 'capath'=>'/etc/ssl/certs')
);
$context = stream_context_create($opts);
//echo print_r($context,true),
// Open the file using the HTTP headers set above
$handle = fopen('https://www.facebook.com/xxxxx', 'rb', false, $context);
if (!$handle)
{
echo '<br>fopen failed<br>';
return false;
}
$bdy = null;
while (!feof($handle))
{
$bdy .= fread($handle, 8192);
}
fclose($handle);