简体   繁体   English

无法在curl请求中设置Cookie

[英]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. 我知道在注册时有验证码,但是那不是问题,当我运行它时,显示“您的会话已过期”似乎是我有一些cookie问题。 i tried tempcookie but still its same.. i not understanding whats the problems. 我尝试了tempcookie,但仍然保持不变。.我不了解问题所在。 if it shows "invalid captcha" or something like that, then its ok. 如果显示“无效的验证码”或类似的内容,则可以。 but its showing Cookie Problem. 但显示Cookie问题。

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. 您可以使用详细输出来比较发送的curl和预期发送的curl。 Maybe the cookies aren't being sent. 可能没有发送Cookie。 Open a file write stream $fp and let curl print to that file a full text of what it's sending and receiving. 打开文件写入流$ fp,然后将所有发送和接收内容的全文打印到该文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM