如何接收验证码图像(使用PHP cURL)

如何接收验证码图像(使用PHP cURL),php,curl,cookies,captcha,php-curl,Php,Curl,Cookies,Captcha,Php Curl,从下面的代码中,即使我尝试了很长时间,也没有得到任何数据。不幸的是,当我查看浏览器时,验证码第一次出现。我尝试刷新页面,但得到一个空白页面 此外,还有另一个名为security2.php的页面,当我刷新这个页面时,我会不断得到一个新的验证码 同样奇怪的是,security和security2.php和3.php我得到了一个空白页面 我的代码: <?php define('COOKIE', './cookie.txt'); header('Content-Type: imag

从下面的代码中,即使我尝试了很长时间,也没有得到任何数据。不幸的是,当我查看浏览器时,验证码第一次出现。我尝试刷新页面,但得到一个空白页面

此外,还有另一个名为security2.php的页面,当我刷新这个页面时,我会不断得到一个新的验证码

同样奇怪的是,security和security2.php和3.php我得到了一个空白页面

我的代码:

<?php
    define('COOKIE', './cookie.txt');
    header('Content-Type: image/png');
    $x=rand(0,1000);
    $url="http://www.turktuccar.com/security2.php?id=$x";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    $cookie = realpath('cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
    curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    $http_headers = array(
        'Host: www.turktuccar.com',
        'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0',
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3',
        'Accept-Encoding: gzip, deflate',
        'DNT: 1',
        'Connection: keep-alive',
    'Cache-Control: max-age=0'
    );
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.turktuccar.com/numara-sorgula/');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
    curl_exec($ch);
    curl_close($ch);
?>

你必须回应
curl\u exec($ch),请尝试以下操作:

<?php
    header('Content-Type: image/png');
    $x=rand(0,1000);
    $url="http://www.xxxxxx.com/security2.php?id=$x";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    echo curl_exec($ch);
    curl_close($ch);
?>

你需要我们做什么?验证码。不幸的是,这是一个空白页。验证码我打算使用我自己的页面你是网站的所有者吗?是的,我是网站的所有者和管理员。请不要删除你的问题,这对未来的用户没有帮助!不幸的是,这种情况没有再次发生。那里的工作很困难。验证码不在乎我做了什么。我不能告诉我为什么。我可以在本地主机上试试吗?。WampServer当然可以,我已经在我的服务器上试过了,上面的代码工作得非常好。您可能想从另一台服务器上尝试,localhost就可以了。在php代码中启用错误报告append
error\u reporting(E\u ALL);ini_集('display_errors','1')和注释
//标题('Content-Type:image/png')它返回什么?
<?php
    header('Content-Type: image/png');
    $x=rand(0,1000);
    $url= file_get_contents("http://www.xxxxxx.com/security2.php?id=$x");
    echo $url;
?>