neel_143 0 Newbie Poster

here is two php pages in which in 1st page i retrieve captcha and submit
and in 2nd page it sends to a url n only then i can login to that site
the problem is that i retrieve captcha successfully
but cant connect to 2nd page
its totally lost the cookie or session n run separately and eventually i failed to login
here is page1 named cap.php-

<?php

set_time_limit(0);

$cookie = 'c:/xampp/htdocs/img/cookie.txt';

$agent = "Opera/9.80 (J2ME/MIDP; Opera Mini/7.1.32052/34.1697; U; en) Presto/2.8.119 Version/11.10";

$uid = $_REQUEST['uid'];
$pwd = $_REQUEST['pwd'];

$ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,"http://ultoo.com/login.php");
        curl_setopt($ch, CURLOPT_TIMEOUT, 0);
       curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

       curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch,CURLOPT_REFERER,"http://ultoo.com/login.php");
               $one=curl_exec($ch);

  preg_match_all("/document.getElementById(.*?).value/",$one,$us);
$user = $us[1][10];

$user = str_replace('(', '', $user);
$user = str_replace(')', '', $user);
$user = str_replace("'", '', $user);

//die("<font color='red'><b>".$user."</b></font>");
flush();

$pass = $us[1][9];

$pass = str_replace('(', '', $pass);
$pass = str_replace(')', '', $pass);
$pass = str_replace("'", '', $pass);


$data1 = "$user=$uid&$pass=$pwd&RememberMe=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://ultoo.com/login.php");    
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, "http://ultoo.com/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"$data1");


$ct = curl_exec( $ch );

if(stristr($ct,"number & password"))
{
echo "<font color='red'><b>Invalid U/P</b></font>";
}
else
{

if(stristr($ct,"secure.php"))
{
curl_setopt($ch, CURLOPT_URL,"http://ultoo.com/secure.php?zxcoiesesscd=");    
curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);

$ct=curl_exec($ch);


preg_match_all("/document.getElementById(.*?).value/",$ct,$mbll);
$mbl = $mbll[1][5];

$mbl = str_replace('(', '', $mbl);
$mbl = str_replace(')', '', $mbl);
$mbl = str_replace("'", '', $mbl);

//die("<font color='red'><b>".$mbl."</b></font>");
flush();

$url = "http://ultoo.com/captcha.php";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
//curl_setopt($ch, CURLOPT_POST, 1);

$html=curl_exec($ch);
curl_close($ch);

$name = "img/".rand(1,99999).".png";
$myFile = $name;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $html;
fwrite($fh, $stringData);
fclose($fh);
}
}
?>
<center>
<img src=<?php
echo $name; ?>><br>
<form method=post action="play.php">
<input type=text name=c>
<input type=hidden name=img value=<?php
echo $name; ?>>
<?php

echo '<input type="hidden" name="mbl" value="'.$mbl.'">';

?>
<input type=submit name="submit" value=Earn>


and here is 2nd page named play.php-


<?php
set_time_limit(0);

error_reporting(0);

$cookie = 'c:/xampp/htdocs/img/cookie.txt';


$c = $_REQUEST["c"];

$mbl = $_REQUEST["mbl"];

$agent = "Opera/9.80 (J2ME/MIDP; Opera Mini/7.1.32052/34.1697; U; en) Presto/2.8.119 Version/11.10";

$ch = curl_init();

$post_data2 = "$mbl=nlp&captcha=$c&loginButton=LOGIN";


   curl_setopt($ch, CURLOPT_URL,"http://ultoo.com/secure.php");    
   curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data2);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_REFERER, "http://ultoo.com/login.php");


$dt = curl_exec($ch);
if(!stristr($dt,"mywallet.php"))
{
die("<font color='red'><b>Wrong Captcha.</b></font>");
flush();
}

?>

can any one give me a perfect solution to this?
i will b thankful to him for lifetime :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.