Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP cURL CURLOPT_文件在cURL_exec()之后为空_Php_Curl_Download_Wget - Fatal编程技术网

PHP cURL CURLOPT_文件在cURL_exec()之后为空

PHP cURL CURLOPT_文件在cURL_exec()之后为空,php,curl,download,wget,Php,Curl,Download,Wget,我正在编写一个用于下载和扫描特定网页元素的脚本。我正在尝试使用PHP cURL下载此示例页面: 但是,每次尝试curl_exec()时,输出文件都是空的。有谁知道这是为什么,或者能够引导我走上修复这一问题的道路吗 我很容易就能在这个函数中使用几乎任何其他URL,这不会发生 function download_page($url, $out_file = "body.txt") { $fp = fopen($out_file, "w"); $ch = curl_init();

我正在编写一个用于下载和扫描特定网页元素的脚本。我正在尝试使用PHP cURL下载此示例页面:

但是,每次尝试curl_exec()时,输出文件都是空的。有谁知道这是为什么,或者能够引导我走上修复这一问题的道路吗

我很容易就能在这个函数中使用几乎任何其他URL,这不会发生

function download_page($url, $out_file = "body.txt") {

    $fp = fopen($out_file, "w");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    
    curl_setopt($ch, CURLOPT_FILE, $fp);

    curl_exec($ch);
    fclose($fp);
    $details = curl_getinfo($ch);
    curl_close($ch);

    return $details;
}

$url = "http://www.jetbull.com/Deposit";
download_page($url);
我在nix环境中运行PHP5.2.6。 我可以清楚地看到页面将返回307,尽管我不确定为什么不遵循重定向(如果这确实是问题的话)

在Firefox中,可以很好地检索此页面,并报告HTTP 200。 服务器是否以cURL无法处理的非标准方式响应,或者cURL是否没有正确地遵循重定向,或者我是否在做其他事情

任何关于如何解决这个问题或引导我走上这条道路的信息的帮助都将非常感谢

添加此选项

curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

$data=curl\u exec($ch);返回$data好的。。?这将把cookie持久化到一个文件中,这在获取正文方面有什么作用?您的脚本返回此错误“curl max(20)redirects followered”,因为您不使用cookie