retrieve captcha and login using curl php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 07, 2013 10:35 pm

retrieve captcha and login using curl php

Postby rahul110392 » Thu Mar 07, 2013 10:38 pm

I am working on a project.So i have to get the captcha code from the site mentioned below.The user will submit the captcha and his login credentials and then i have to extract the data(for user's benefits). But after i submit the captcha,simply the login page appears and nothing happens.

i have tried this with multiple sites and simply the login page appears. I know how to fetch data after logging in,but the captcha is really giving a headache

Code: Select all


function open($url)

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070219 Firefox/');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIE, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie);
    curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt ($ch, CURLOPT_REFERER, $url);
    $result = curl_exec($ch); 

    return $result;

function between($string, $start, $end)
    $out    = explode($start, $string);

        $string = explode($end, $out[1]);
        echo $string[0];
        return $string[0];

    return '';

function get_captcha()
    $url    = '';

    $open   = open($url);

    $code   = between($open, '<img src='', '">');

   // echo '' . $code;

    return '' . $code;
   //return ;


function rahul()

    echo $capth;



$postdata = "regno=".$username."&passwd=".$password."&vrfcd=".$veri."&submit=".$com;

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);  // <-- add this line
curl_setopt ($ch, CURLOPT_REFERER, $url);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);

echo $result; 

$data = curl_exec($ch);



<form action="" method="post">
<img src="<?php echo get_captcha(); ?>" border="0" /><br />
<input type="text" name="code" value="<?= isset($_POST['code']) ? htmlspecialchars($_POST['code']) : '' ?>" /><br />
<input type="submit" name="submit" value="submit"/>


if(isset($_POST['submit'])) {

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests