Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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-空输出,无错误_Php_Curl - Fatal编程技术网

PHP CURL-空输出,无错误

PHP CURL-空输出,无错误,php,curl,Php,Curl,我没有得到有效url的curl输出, 示例$url= 您是否真的在某个时候输出了$error\u no?添加它是为了检查任何错误是的,但您是否真的在某处输出了结果?使用上面的代码,您将不会看到error我从getURL方法获得了输出。感谢heart_hacker和pekkaI浪费了很多时间。就我而言,这个设置ssl验证器是修复curl_setopt($ch,CURLOPT_ssl_VERIFYPEER,false);我也有类似的问题。谢谢,你的代码运行得很好。但是你能解释一下问题代码中的错误吗?

我没有得到有效url的curl输出, 示例$url=


您是否真的在某个时候输出了
$error\u no
?添加它是为了检查任何错误是的,但您是否真的在某处输出了结果?使用上面的代码,您将不会看到error我从getURL方法获得了输出。感谢heart_hacker和pekkaI浪费了很多时间。就我而言,这个设置ssl验证器是修复curl_setopt($ch,CURLOPT_ssl_VERIFYPEER,false);我也有类似的问题。谢谢,你的代码运行得很好。但是你能解释一下问题代码中的错误吗?你的代码为什么工作得很好?你应该解释原因
curl\u setopt($ch,CURLOPT\u FOLLOWLOCATION,1)在卷曲后重定向您。最像你忘了在你的URL后面加一个“/”。
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,           "$url");
curl_setopt($ch, CURLOPT_TIMEOUT,       60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$referer = WebCrawl::getRandomURL();
curl_setopt($ch, CURLOPT_REFERER,       $referer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_COOKIEJAR,     "cookie.txt");

curl_setopt($ch, CURLOPT_USERAGENT,     "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

$body = curl_exec($ch);
$error_no = curl_errno($ch);
function getURL($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        $tmp = curl_exec($ch);
        curl_close($ch);
        if ($tmp != false){
            return $tmp;
        }
    }