首页 > 解决方案 > php curl 输出 ehco 它自己

问题描述

我编写了一个 php curl 函数,用于从 ssl 启用站点下载网页。它不像我想要的那样工作。即使我没有在其他地方使用 echo 命令,它也会自动回显。我想使用此功能保存下载页面,但它保存 1 个文件而不是全部数据。

我已经用谷歌搜索过这个问题,但没有成功。写堆栈溢出对我来说总是最后的选择,由于我的英语不好以及解释不好,我总是避免

function gssl($target_url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
    curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\PC\Desktop\ssl\cacert-2019-05-15.pem');
    //curl_setopt($ch, CURLOPT_CAINFO, 'https://curl.haxx.se/ca/cacert-2019-05-15.pem');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_VERBOSE,true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    $html= curl_exec($ch);
    return $html;
    }

function write($post,$myFile){
$fh = fopen($myFile, 'a+') or die("can't open file");
fwrite($fh, $post);
fclose($fh);
}

标签: phpcurl

解决方案


将 CURLOPT_RETURNTRANSFER 设置为 true


推荐阅读