问题描述
我已为此网站创建了注册脚本。
我知道有寄存器captcha,但这不是问题,当我运行它,它显示您的会话已过期
它似乎我有一些cookie的问题。我尝试tempcookie但仍然是同样的。
我不明白什么问题。
如果它显示无效captcha或类似的,那么它的确定。但它显示Cookie问题。
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.
这里是代码。
//$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="[email protected]";
$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;
推荐答案
您可以使用详细输出来比较curl正在发送相比你期望被发送。也许cookies没有发送。打开一个文件写流$ fp,并让curl打印到该文件发送和接收的全文。
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 );
这篇关于无法在curl请求中设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!