简体   繁体   中英

How can I receive captcha image (using PHP cURL)

From the code you see below, even though I tried for a long time, I do not get any data. Unfortunately, when I view the browser a captcha comes the first time. I tried refreshing the page but I get a blank page.

In addition, there is another page called security2.php and when I refresh this page, I constantly get a new captcha.

Also strange, security and security2.php and 3.php I'm getting a blank page.

My Code:

<?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);
?>

You've to echo curl_exec($ch); , try this instead:

<?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);
?>

UPDATE:

Based on your comments, you don't have curl installed on php. You can use file_get_contents() instead, ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM