Curl Post 数据的问题

5 views
Skip to first unread message

xjflyttp

unread,
Jul 2, 2008, 9:37:02 AM7/2/08
to cnPhpDevelop
目的...
生成一个线性的Key Post 到 mcafee 的登录页面 “https://secure.nai.com/apps/downloads/
my_products/checkgrantnumber.asp?region=us&segment=enterprise”
登录页面位于 https://secure.nai.com/apps/downloads/my_products/login.asp 作为引用
页发送过去

问题...
Post过去以后返回的数据是 302 目标被转移....
浏览器访问则并没有这个问题....

分析...
试过把浏览器的cookie清除...访问目标页面...观察只有一个ASP的Session ID写入...
用Curl 把这个Session ID也发送过去仍然是目标已转移....302...................

.......................................



<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 'true');
ini_set('max_execution_time', 0);

//校验是否可用...
function isAvailable($string) {
//
if ( (stripos($string, '<!-- Expire Grant Numbers -->') === false )
&& //不应该找到过期信息
(stripos($string, '<!-- Invalid Grant Numbers -->') === false )
&& //不应该找到不正确号码
(stripos($string, 'View Available Downloads') !== false ) ) { //应该
找到 浏览可用下载
return true;
} else {
return false;
}
}

//提取产品名称
function analyzeTitle($string) {
//模板
$pattern = '/.*<p class=\"prodLink\"><a href=
\"javascript:ButtonClicked\(\'([^\']+)\',\'[a-zA-Z0-9]+\'\);">([^\<]+)<
\/a><\/p>.*/';

//初始化
$retArray = null;

//正则
$retMatch = preg_match_all($pattern, $string, $retArray);

print_r($retMatch);

//提取结果
return $retMatch[1][0];
}

//写入到文件
function addToFile($title, $key) {
//
global $fp;//声明全局变量
fwrite($fp, trim($key). "\t" . trim($title) . "\n");
}

//主函数
function myMainFunction($start, $len) {

//开始一个循环.len次
$endNumber = $start + $len;
for ($i = $start; $i < $endNumber; $i++) {
echo "Now is $i\n";
//
$GenGrantNumber = $i . '-NAI';

//初始化ch变量
$ch = null;

//实例化curl对象
$ch = curl_init();

$url = 'https://secure.nai.com/apps/downloads/my_products/
checkgrantnumber.asp?region=us&amp;segment=enterprise';
$refer = 'https://secure.nai.com/apps/downloads/my_products/
login.asp';

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回数据
//curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);//
代理
//curl_setopt($ch, CURLOPT_HEADER, 0);//头信息
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);//关闭校验ssl

//curl_setopt($ch, CURLOPT_COOKIE,
'ASPSESSIONIDQACRAAAT=HNBDCCPCEEJCDFCAEAEMNDGP');//cookie信息

curl_setopt($ch, CURLOPT_POST, 1);//post数据打开
//curl_setopt($ch, CURLOPT_POSTFIELDS, 'GrantNumber='.
$GenGrantNumber .'&submit=Submit');//post数据内容

$post = Array();
$post['GrantNumber'] = urlencode($GenGrantNumber);
$post['submit'] = urlencode('Submit');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

//发送请求
$returnString = curl_exec($ch);

//debug....
//echo nl2br(htmlspecialchars($returnString));
//echo htmlspecialchars($returnString);
//var_dump(isAvailable($returnString));

//序列号是否可用
if (isAvailable($returnString)) { //可用
$productTitle = analyzeTitle($returnString);
$productKey = $GenGrantNumber;

//
echo $productTitle . "&nbsp;" . $productKey . "\n\n";

//
addToFile($productTitle, $productKey);//追加到文件
} else {
//留空
echo "$GenGrantNumber is wrong.\n\n";
}

//关闭连接..
curl_close($ch);
}
}

$min = 1359133;
$len = 1;

$fp = fopen('keyList.txt', 'wb');
fwrite($fp, "From $min to $len");
myMainFunction($min, $len);
fclose($fp);//关闭


//success
//<p class="prodLink"><a href="javascript:ButtonClicked('McAfee Total
Protection Service - Adv.','10111');">View Available Downloads</a></p>
//<p class="prodLink"><a href="javascript:ButtonClicked('McAfee Active
VirusScan SMB Edition','10049');">View Available Downloads</a></p>

//faild message.....
//<!-- Invalid Grant Numbers -->
//<!-- Expire Grant Numbers -->

?>
Reply all
Reply to author
Forward
0 new messages