3

I'm trying to get the HTML source from a website using PHP, I've tried the following code and it works correctly for google.com and other websites, but it does not work for facebook.com

What am I missing?

<?php
    $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL,'www.facebook.com');
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0');
    $query = curl_exec($curl_handle);
    curl_close($curl_handle);
    $query =  htmlentities($query);
    echo $query;
?>
durron597
  • 31,968
  • 17
  • 99
  • 158
MalekDev
  • 33
  • 1
  • 4
  • Perhaps you could retrieve and look at the headers of your request. There might be something useful in there. – Jonathan Kuhn Nov 08 '13 at 17:29
  • If you wouldn't mind avoiding "gonna" and "plz" in questions, that is generally appreciated here. This isn't a chat room `:)`. – halfer Nov 08 '13 at 17:35

1 Answers1

0

That is because facebook runs on HTTPS (SSL Protocol) . Add this to your existing cURL parameters

curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126