简体   繁体   English

PHP CURL始终返回null

[英]PHP CURL always returns null

I want to get any page of this web site: http://alhayat.com using curl. 我想使用curl获得该网站的任何页面: http ://alhayat.com。

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. 但是返回值始终为null。

I tried to find a solution, but nothing worked. 我试图找到一个解决方案,但没有任何效果。

Any ideas? 有任何想法吗?

Just delete the line 只需删除行

$data = json_decode($data, true);

that will return the site as return value 将返回站点作为返回值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM