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!

5
  • 1
    Worked fine for me. Can you show the full error message. Commented May 26, 2014 at 15:46
  • stupid ssl , stackoverflow.com/a/7123591/594423, thnx , but curl still fails Commented May 26, 2014 at 15:56
  • 1
    curl fails because you need to specify the option CURLOPT_SSL_VERIFYPEER to false for curl_setopt Commented May 26, 2014 at 15:59
  • please post it as answer. that was it. thank you! Commented May 26, 2014 at 16:02
  • add standard security considerations for doing curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); stackoverflow.com/questions/13740933/… Commented Jul 17, 2014 at 15:41

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

add standard security considerations for doing curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); stackoverflow.com/questions/13740933/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.