簡體   English   中英

卷曲發布用戶名/密碼登錄

[英]Curl post username/password to login

我想使用Curl(或其他方法)將登錄詳細信息發送到登錄頁面。 這是我正在使用的代碼。

<?php
$username='myMAIL/USERNAMEhere'; 
$password='myPASSWORDhere'; 
$postdata = 'username='.$username.'&password='.$password;

// INIT CURL
$ch = curl_init();

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL,     'https://secure.runescape.com/m=weblogin/loginform.ws?        mod=www&ssl=1&expired=0&dest=account_settings.ws?jptg=ia&jptv=navbar');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);

// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);

// CLOSE CURL
curl_close ($ch); 

if ($store=='') {

//username and password are valid
//if login is valid, hotfile website returns nothing
echo '<br><i>Login Works!! Enjoy.</i>';

} else {

//username and password are not valid
//if username or password is invalid, the website returns 
//invalid username or password page
echo '<br><i>Login does not work.</i>';

}

?>

但它一直說登錄詳細信息有誤,而沒有。

這是具有合法用戶名/密碼的演示: http : //jaydz.me/test2/

你需要:

$postdata = 'username='.$username.'&password='.$password;

編輯:

在您的鏈接示例中,您嘗試使用curl復制的表單包括所有參數作為隱藏字段,即,它們都作為POST參數發送。

$fields = array(
    'username='. urlencode($username),
    'password=' . urlencode($password),
    'mod=www',
    'ssl=1',
    'expired=0',
    'dest=' . urlencode('account_settings.ws?jptg=ia&jptv=navbar')
);
$postdata = implode('&', $fields);

如果您可以通過瀏覽器登錄到該頁面,則應嘗試使用chrome dev工具檢查請求。 您應該能夠看到發送的確切POST數據。

可能是您嘗試過POST的服務基於用戶代理標頭之類的其他東西拒絕了您的請求。 在這種情況下,您的curl請求應該嘗試並盡可能接近地復制瀏覽器請求。 再次,檢查所有以chrome發送的標頭,並將其添加到curl請求中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM