2

经过几个小时的研究和试验,我必须寻求帮助。我有这种情况:我想使用 cURL 登录网站,但每次都得到登录页面。登录页面非常简单,只有 2 个输入表单和一个按钮。我必须说该按钮有一个 javascript 事件 OnSubmitDonStuff() ...但我使用 TamperData 查看标题..这是我的代码:

$post_data = array();
$post_data['action'] = "login";
$post_data['email'] = "myemail@gmail.com"; 
$post_data['password'] = "mypass"; 
$postthis = http_build_query($post_data);

//URLS
$host = "passwordwebsite.com";
$url = "http://passwordwebsite.com";
$loginReferer = "http://passwordwebsite.com";
$reputationUrl = "http://passwordwebsite.com/dashboard";

// The User-Agent string to send
$userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
// Create temp file to store cookies 
$cookieJar = dirname(__FILE__) . '/cookiez_.tmp';
// URL to login page 

// Create the cURL handle for login
$ch = curl_init();

// Set connection meta
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postthis); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

// Set header-related options
curl_setopt($ch, CURLOPT_REFERER, $loginReferer);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar);

// Set connection meta
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1); // debug headers sent

$timeout = 5;
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 ); //stop if an error occurred

curl_setopt($ch, CURLOPT_URL, $reputationUrl); 

$response = curl_getinfo( $ch );

// Execute the request
if (!$result = curl_exec($ch)) {
    exit("ERROR: Reputation scrape request failed: " . curl_error($ch));
}

// Output the result
echo $result;

结果仍然是登录页面,这是我得到的标题:

HTTP/1.1 303 See Other
Server: nginx
Date: Sun, 13 Oct 2013 08:09:09 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Location: /
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 13 Oct 2013 08:09:09 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
Set-Cookie: ps_auth=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=passwordwebsite.com; httponly
4

0 回答 0