user3231235
user3231235

Reputation: 37

PHP CURL always returns null

I want to get any page of this web site: http://alhayat.com using curl.

This my code so far:

ini_set('display_errors',1);
error_reporting(E_ALL);
error_reporting(E_STRICT);
function getData($url){
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => 1, 
        CURLOPT_FOLLOWLOCATION => 1,
        CURLOPT_COOKIESESSION => true,
        CURLOPT_FILETIME => true,
        CURLOPT_CONNECTTIMEOUT => 55,
        CURLOPT_FAILONERROR => 0,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_TIMEOUT => 45,
        CURL_HTTP_VERSION => true,
        CURLOPT_HEADER => true,
        CURLOPT_BINARYTRANSFER => true,
    ));

    $data = curl_exec($ch);

    if(curl_errno($ch))
    {
        echo 'error:' . curl_error($ch);
    }

    curl_close($ch);

    $data = json_decode($data, true);

    return $data;
}
$url = 'http://alhayat.com';
var_dump(getData($url));

but the return value is always null.

I tried to find a solution, but nothing worked.

Any ideas?

Upvotes: 0

Views: 1398

Answers (1)

bensch
bensch

Reputation: 28

Just delete the line

$data = json_decode($data, true);

that will return the site as return value

Upvotes: 1

Related Questions