Unable to set Cookie in curl Request

早过忘川 提交于 2019-12-23 05:06:50

问题


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;

回答1:


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


来源:https://stackoverflow.com/questions/17143650/unable-to-set-cookie-in-curl-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!