GGG GGG - 9 months ago 30
PHP Question

PHP - cURL request not working

I'm trying to use cURL in PHP to retrieve the HTML of

https://www.facebook.com/video.php?v=720617444660843
, but it's not printing nothing and
curl_error
is returning nothing.

This is the code I'm using:

$defaults = array(
CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);

$ch = curl_init();
curl_setopt_array($ch, $defaults);
if( ! ($result = curl_exec($ch)))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
echo $result;

Answer Source

You need to pass user agent

$defaults = array(
CURLOPT_URL => "https://www.facebook.com/video.php?v=720617444660843",
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \ Chrome/24.0.1304.0 Safari/537.16'
);