1

I am browsing Github info/docs but cant find any simple example on how to get contents of a raw Github file.

For example if I try to use

$url ="https://raw.githubusercontent.com/octocat/Spoon-Knife/master/index.html";

echo file_get_contents($url);

I get failed to open stream: HTTP...

If I use curl same thing 404 page. So obviously I have to use API but there is just no simple example on how to do it. Can someone please post plain example. Thank you!

Benn
  • 4,840
  • 8
  • 65
  • 106
  • 1
    Worked fine for me. Can you show the full error message. – Rahil Wazir May 26 '14 at 15:46
  • stupid ssl , http://stackoverflow.com/a/7123591/594423, thnx , but curl still fails – Benn May 26 '14 at 15:56
  • 1
    curl fails because you need to specify the option `CURLOPT_SSL_VERIFYPEER` to `false` for `curl_setopt` – Rahil Wazir May 26 '14 at 15:59
  • please post it as answer. that was it. thank you! – Benn May 26 '14 at 16:02
  • add standard security considerations for doing curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); http://stackoverflow.com/questions/13740933/security-consequences-of-disabling-curlopt-ssl-verifyhost-libcurl-openssl – dreftymac Jul 17 '14 at 15:41

1 Answers1

2

You can use a different method to escape SSL validation and add more options if you want, with CURL function.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://raw.githubusercontent.com/octocat/Spoon-Knife/master/index.html');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

echo $data;

Works fine for me here, you just need to enable, if was not, the curl extension.

IgorCarvalho
  • 136
  • 4
  • add standard security considerations for doing curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); http://stackoverflow.com/questions/13740933/security-consequences-of-disabling-curlopt-ssl-verifyhost-libcurl-openssl – dreftymac Jul 17 '14 at 15:40