PHP cURL返回包含正确POST数据的意外结果

PHP cURL返回包含正确POST数据的意外结果,php,curl,Php,Curl,我发现了一个提供截屏服务的网站。我想从许多URL批量请求屏幕截图,因此我编写了一个PHP cURL脚本,以编程方式实现这一点 为了从该web服务获取屏幕捕获图像,它需要带有安全代码的POST数据和需要捕获的网站URL 下面的代码是执行上述两个操作的cURL脚本 $url = 'http://ctrlq.org/screenshots/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CU

我发现了一个提供截屏服务的网站。我想从许多URL批量请求屏幕截图,因此我编写了一个PHP cURL脚本,以编程方式实现这一点

为了从该web服务获取屏幕捕获图像,它需要带有安全代码的POST数据和需要捕获的网站URL

下面的代码是执行上述两个操作的cURL脚本

$url = 'http://ctrlq.org/screenshots/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
preg_match('/<input type="hidden" name="labnol" value="(.*)" \/>/', $content, $match);
$postData = array(
    'labnol' => $match[1],
    'url' => 'http://www.google.com'
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_exec($ch);
$content2 = curl_exec($ch);
curl_close($ch);

echo $content2;
$url='1!'http://ctrlq.org/screenshots/';
$ch=curl\u init($url);
curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content=curl\u exec($ch);
preg_match('/',$content,$match);
$postData=数组(
“labnol”=>$match[1],
'url'=>'http://www.google.com'
);
curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postData);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookieFile);
curl_exec($ch);
$content2=curl\u exec($ch);
卷曲关闭($ch);
echo$content2;
不幸的是,我得到了源代码:

Sorry but the tool couldn't capture that web page. Please <a href='/screenshots/'>try another URL</a>.
很抱歉,工具无法捕获该网页。请
虽然成功代码应包含屏幕捕获图像链接:

<div class="animate" id="progressmeter">
                          <div class="progress progress-striped active">
                            <div class="bar" style="width: 0%;"></div>
                          </div>
                        </div>
                        <script>
                            var progress = setInterval(function() {
                            var $bar = $('.bar');
                            if ($bar.width()==300) {
                                clearInterval(progress);
                                $('.progress').removeClass('active');
                                document.getElementById('progressmeter').innerHTML = "<a class='btn btn-success btn-large' href='http://ctrlq.org/files/screenshots/0e82990496751f51e3329094b26bd4a1.png' target='_blank'><i class='icon-download icon-white'></i> Download Image</a>  <a class='btn-large btn btn-info' href='/screenshots/'><i class='icon-camera icon-white'></i> New Capture</a>";
                            } else {
                                $bar.width($bar.width()+30);
                            }
                            $bar.text($bar.width()/3 + 10 +  "%");
                            }, 1500);
                        </script>

var progress=setInterval(函数(){
变量$bar=$('.bar');
如果($bar.width()==300){
清除间隔(进度);
$('.progress').removeClass('active');
document.getElementById('progressmeter')。innerHTML=“”;
}否则{
$bar.width($bar.width()+30);
}
$bar.text($bar.width()/3+10+“%”);
}, 1500);

我想问一下这个卷曲脚本有没有错误?谢谢。

您忘记处理会话cookies。 使用


开始时。

您忘记处理会话cookie。 使用

一开始

curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");