我是新鲜的,经过了许多辅导。 我最后试图使用以下法典:
<?php
// INIT CURL
$url="";
function login($url) {
$result = "";
$cookiePath = "/tmp/cookies.txt";
// Initialize the page
$page = curl_init();
// Set some options
curl_setopt($page, CURLOPT_COOKIESESSION, true);
curl_setopt($page, CURLOPT_REFERER, http://www.justanswer.com/login.aspx );
curl_setopt($page, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($page, CURLOPT_FRESH_CONNECT, true);
curl_setopt($page, CURLOPT_HEADER, true);
curl_setopt($page, CURLOPT_POST, true);
curl_setopt($page, CURLOPT_RETURNTRANSFER, true);
curl_setopt($page, CURLOPT_CONNECTTIMEOUT, 30);
$pattern = "#Set-Cookie: (.*?; path=.*?;.*?)
#";
preg_match_all($pattern, $result, $matches);
array_shift($matches);
$cookie = implode("
", $matches[0]);
// Use the parsed cookies with the next request
curl_setopt($page, CURLOPT_COOKIE, $cookie);
curl_setopt($page, CURLOPT_COOKIESESSION, true);
curl_setopt($page, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($page, CURLOPT_FRESH_CONNECT, true);
curl_setopt($page, CURLOPT_HEADER, false);
curl_setopt($page, CURLOPT_POST, false);
// Set the URL
curl_setopt($page, CURLOPT_URL, $url);
// Set the location of and send the cookies
curl_setopt($page, CURLOPT_COOKIEJAR, $cookiePath);
curl_setopt($page, CURLOPT_COOKIEFILE, $cookiePath);
// Send out POST data
curl_setopt($page, CURLOPT_POST, 1);
curl_setopt($page, CURLOPT_POSTFIELDS, "__EVENTTARGET=&__EVENTARGUMENT=&__SSVIEWSTATE=18&__VIEWSTATE=&email=****&sign_in_type=returning&username=&password=****&remember=true&ctl00%24BodyContent%24btnLogin.x=99&ctl00%24BodyContent%24btnLogin.y=17&SC_SID=346833306&SC_GUID=d157264a-24e2-47c0-b545-259ea5298e19&JS_BOOL=true&__EVENTVALIDATION=%2FwEWAwL%2BraDpAgKUnpuXBgKp%2F%2BSDCG4uM7n2SYrFbuk10%2FLkC64jclbvH6dXKmxM06VHN92G");
// Get the page
return $page;
}
$page = login($url);
// Go to the page and log in
curl_exec($page);
// Change the URL to the main page to check to see if the user is logged in
curl_setopt($page, CURLOPT_URL, "");
// Print the output
print curl_exec($page);
?>
请允许我解释一下,我做了什么错了,我重复了同一份POST申请,利用Live HTTP头脑延伸到火f上,是成功的。
Login page at http://www.justanswer.com/login.aspx。
请建议
TIA