0

我为此站点创建了一个注册脚本。我知道注册时有验证码,但这没问题,当我运行它时,它显示“您的会话已过期”,似乎我有一些 cookie 问题。我试过 tempcookie 但还是一样。我不明白是什么问题。如果它显示“无效的验证码”或类似的东西,那么它就可以了。但它显示 Cookie 问题。

这是代码。

//$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;
4

1 回答 1

0

您可以使用详细输出来比较 curl 发送的内容与您期望发送的内容。也许cookie没有被发送。打开一个文件写入流 $fp 并让 curl 向该文件打印它正在发送和接收的内容的全文。

/* 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 );
于 2013-08-19T21:36:15.490 回答