$myusername = "myusername";
$mypassword = "mypassword";
$site_url = "https:// my site url";
$cookiefile = "cookie_filename.txt";
$uagent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//----------1st request start---------
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site_url);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$myusername.'&password='.$mypassword.'&generalbutton=Login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$res = curl_exec($ch);
curl_close ($ch);
//----------1st request end---------
//----------2nd request start---------
$m = explode("jsessionid=",str_replace("Content-Length:","",$res));
$sessId = explode(" ",trim($m[1]));
$headers_curl = array(
"Accept-Encoding: .....",
"Accept-Language: .....",
"Accept: .....",
"Set-Cookie: SESSIONIDS=".trim($sessId[0])."",
"Path=....",
"Cache-Control: max-age=0",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https:// my 2nd url");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$myusername.'&password='.$mypassword.'&jsessionid='.trim($sessId[0]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl);
curl_setopt($ch, CURLOPT_REFERER, "https://my refer url");
curl_exec($ch);
//----------2nd request end--------
//----------3rd request start---------
curl_setopt($ch, CURLOPT_URL,$site_url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$myusername.'&password='.$mypassword.'&jsessionid='.trim($sessId[0]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl);
curl_setopt($ch, CURLOPT_REFERER, "https:// my refer url");
$result = curl_exec($ch);
//----------3rd request end---------
//----------4th request start ---------
curl_setopt($ch, CURLOPT_URL,"https:// my 4th url");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$myusername.'&password='.$mypassword.'&jsessionid='.trim($sessId[0]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl);
curl_setopt($ch, CURLOPT_REFERER, "https:// my refer url");
$Tempresult = curl_exec($ch);
//----------4th request end---------
//----------5th request start---------
preg_match_all('/<form(.*?)<\/[\s]*form>/s',$Tempresult,$livedata);
preg_match_all('/value=.*?(.*)|">/',$livedata[1][7],$finaldata);
preg_match_all('/div id=.*?(.*)|">/',$livedata[1][7],$divdata);
$finaldata[1] = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $finaldata[1]);
$divdata[1] = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $divdata[1]);
$numChkURL ="https:// my 5th url &data1=".$finaldata[0][1]."&data2=".$finaldata[0][2]."&data3=".$divdata[0][1]."&_=";
curl_setopt($ch, CURLOPT_URL,$numChkURL);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.$myusername.'&password='.$mypassword.'&jsessionid='.trim($sessId[0]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl);
curl_setopt($ch, CURLOPT_REFERER, "https:// my refer url");
$numChkResult = curl_exec($ch);
//----------5th request end---------
//---------6th request start----------
preg_match_all('/<input(.*?)<\/td>/s',$numChkResult,$chkData);
preg_match_all('/value=.*?(.*)|\/>/',$chkData[1][1],$chkFinaldata);
$chkFinaldata[1] = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $chkFinaldata[1][0]);
$searchURL = "https://my 6th url?data1=".$finaldata[0][1];
$searchPostData = 'username='.$myusername.'&password='.$mypassword.'&data1='.$finaldata[0][1].'&data2='.$finaldata[0][2].'&data3='.$chkFinaldata[1];
curl_setopt($ch, CURLOPT_URL,$searchURL);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $searchPostData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_curl);
curl_setopt($ch, CURLOPT_REFERER, " http:// my refer url");
$searchChkResult = curl_exec($ch);
//---------6th request end----------
(注意:基于$ Tempresult响应我的第5个请求必须启动(第5个请求必须等到$ Tempresult响应) 然后基于$ Tempresult&amp; $ numChkResult响应我的第6个请求必须启动(第6个请求必须等到$ Tempresult&amp; $ numChkResult响应))