简体   繁体   中英

Unable to set Cookie in curl Request

i have created a Register script for this site. i know there have captcha at register, but thats not problem, when i running it, its showing "Your Session Expired" its seems that i have some cookie problem. i tried tempcookie but still its same.. i not understanding whats the problems. if it shows "invalid captcha" or something like that, then its ok. but its showing Cookie Problem.

here is the codes.

//$cn = str_replace(".","",$_SERVER['REMOTE_ADDR']);
//$finalcookie = "coki/".$cn.".txt";
$finalcookie = tempnam("/tmp", "CURLCOOKIE");

$url="http://www.ypox.com";
$login="$url/content/login.html";
$signup="$url/content/signup.action";

$agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";          

    $ch = curl_init();          
    curl_setopt($ch, CURLOPT_URL, $login);          
    curl_setopt($ch, CURLOPT_COOKIEJAR, $finalcookie);        
    curl_setopt($ch,CURLOPT_ENCODING,"gzip,deflate");         
    curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);          
    curl_setopt($ch, CURLOPT_REFERER, $login);          
    $html=curl_exec($ch);

//echo $html;

//echo '<img src=captcha.php><br>';

$name="Rahul";
$email="rahul12345@gmail.com";
$mobile="8798147385";
$cap="captcha";

$data="hidGen=Mr&tfUserName=$name&tfMobileNum=$mobile&tfUserID=$email&date1=10%2F10%2F1980&tfReferCode=&textcode=$cap&checkaccept=on";               

      curl_setopt($ch, CURLOPT_URL, $signup);
      curl_setopt($ch, CURLOPT_USERAGENT, $agent);
      curl_setopt($ch, CURLOPT_COOKIEJAR,$finalcookie);
      curl_setopt($ch, CURLOPT_COOKIEFILE,$finalcookie);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_REFERER, $login);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $html=curl_exec($ch);

echo $html;

You could use verbose output to compare what curl is sending compared to what you expect to be sent. Maybe the cookies aren't being sent. Open a file write stream $fp and let curl print to that file a full text of what it's sending and receiving.

/* in your setup */
$fp = fopen ( 'somefile.txt', 'w' );
/* then later in your code, only once in first group */
curl_setopt ( $ch, CURLOPT_VERBOSE, true );
curl_setopt ( $ch, CURLOPT_STDERR, $fp );

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