如何使用PHP cURL显示网站并获取内容?

时间:2016-11-08 11:44:03

标签: php curl

我需要展示一个网站并获取一些内容。为此,我尝试了PHP cURL并在localhost中运行但结果却没有得到。目前,结果是获得bool(false)

的index.php

$url = "https://www.test-data.de/test/data?_ts=4664397-1478603498594&Command=start";
//use curl to get html content
function getUrlContent($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/cookies.txt');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return ($httpcode>=200 && $httpcode<300) ? $data : false;
}

$results                             = getUrlContent($url);
var_dump($results);

0 个答案:

没有答案