2017-05-03 14 views
2

でログインできません:PHPは、私がページ上でこのフォームを持っているカール

ここ
<form name="logForm" method="post" action="j_security_check" onsubmit="return validateLogin(this);" _lpchecked="1"> 
    <input type="hidden" name="j_username"> 
    <input type="hidden" name="catId" value="10000"> 
    <input type="hidden" name="redURL" value="/loggedIn.do">  
     <table border="0" bordercolor="pink" id="login-table"> 
      <tbody><tr> 
       <td><input id="userId" type="text" name="username" class="login-fields phfield" value="username"></td> 
       <td><input id="pwd" type="password" name="j_password" class="login-fields phfield" value="password"></td> 
       <td rowspan="2" style="width: 105px;"> 
        <input type="submit" value="" class="login_btn" id="login-submit"> 
       </td> 
      </tr> 
     </tbody></table> 
    </form> 

、隠されたj_usernameと入力された名前ユーザ名の違いは何ですか?私は "username"を投稿する必要がありますか?

だから、私はVARSを設定し、ログインをしてみてください。このフォームについて:

$cookiefile = tempnam ("/tmp", "mycookiefile.txt"); 
$login = 'https://example.com/folder/j_security_check'; 
$cookiedata = array(
"username" => "myusername", 
"j_password" => "mypassword" 
); 

// try to login 
$ch = curl_init ($login); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
$verbose = fopen('verbose.txt', 'w+'); 
curl_setopt($ch, CURLOPT_STDERR, $verbose); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt ($ch, CURLOPT_POST, true); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $cookiedata); 
$out = curl_exec ($ch); 
$headers = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

      if ($headers == 404 || curl_errno($ch) != 0) 
      { 
        echo "Error \n"; 
      } 
echo $out; 

私はそれがログイン失敗ページにリダイレクトし、ログインすることができません。

どうか間違っていますか?おかげ

冗長:

* About to connect() to example.com port 443 (#0) 
* Trying xxx.xxx.xxx.xxx... 
* Connected to example.come (xxx.xxx.xxx.xxx) port 443 (#0) 
* Initializing NSS with certpath: sql:/etc/pki/nssdb 
* CAfile: /etc/pki/tls/certs/ca-bundle.crt 
    CApath: none 
* SSL connection using TLS_RSA_WITH_AES_128_GCM_SHA256 
* Server certificate: 
* subject: CN=*.example.com 
* start date: Aug 10 00:00:00 2016 GMT 
* expire date: Aug 10 23:59:59 2017 GMT 
* common name: *.example.com 
* issuer: CN=RapidSSL SHA256 CA,O=GeoTrust Inc.,C=US 
> POST /folder/j_security_check HTTP/1.1 
Host: example.com 
Accept: */* 
Content-Length: 370 
Expect: 100-continue 
Content-Type: multipart/form-data; boundary=----------------------------e6df4811bbdc 

< HTTP/1.1 100 Continue 
< HTTP/1.1 302 Found 
< Date: Wed, 03 May 2017 14:38:21 GMT 
< X-Powered-By: Servlet/3.0 
< Location: https://example.com/folder/loginFailure.do 
< Content-Length: 0 
* Added cookie logged-user="""" for domain example.com, path /, expire 786297600 
< Set-Cookie: logged-user=""; Expires=Thu, 01-Dec-94 16:00:00 GMT; Path=/; Domain=example.com 
* Added cookie JSESSIONID="0000CKKhQSS79AIRXhTP-REhHSI:18hmtvfl9" for domain example.com, path /, expire 0 
< Set-Cookie: JSESSIONID=0000CKKhQSS79AIRXhTP-REhHSI:18hmtvfl9; Path=/; HttpOnly 
< Expires: Thu, 01 Dec 1994 16:00:00 GMT 
< Cache-Control: no-cache="set-cookie, set-cookie2" 
< Content-Type: text/plain 
< Content-Language: en-US 
* HTTP error before end of send, stop sending 
< 
* Closing connection 0 

ブラウザでログインしたとき、これらはクロームによってコピーされたカールです...

//homepage 

curl "https://example.com/folder/viewHome.do" -H "Accept-Encoding: gzip, deflate, sdch, br" -H "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Referer: https://example.com/" -H "Cookie: JSESSIONID=0000IqYX1pKkYILlDsHqo2TfZLO:18hmtvhe1; LtpaToken2=... ...; LtpaToken=... ...; logged-user=myuser" -H "Connection: keep-alive" --compressed 

//j_security_check 
curl "https://example.com/folder/j_security_check" -H "Cookie: JSESSIONID=0000IqYX1pKkYILlDsHqo2TfZLO:18hmtvhe1; LtpaToken2=tokenLongString... ...; LtpaToken=tokenLongString... ..." -H "Origin: https://example.com" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: max-age=0" -H "Referer: https://example.com/folder/viewHome.do" -H "Connection: keep-alive" --data "j_username=myuser^&catalogId=10000^&redirectURL=^%^2FloggedIn.do^&username=myuser^&j_password=mypassword" --compressed 
+0

あなたは、ファイルへの冗長出力をしましたが、出力のいずれかを含みません。あなたの質問にverbose.txtの内容を追加してください。 – Luke

+0

@ルークは冗長を追加しました...ありがとうございます – kenwarr

+0

「送信終了前のHTTPエラー、送信停止」行は、応答がターゲットサーバによって終了されたことを示唆しています – Luke

答えて

0

あなたは、JavaScriptのメソッドのコードを提供する必要があり、validateLogin()。

j_usernameは、非表示であり、ユーザーがアクセスできません。可視入力... name="username" ...は、ユーザーが提供するユーザー名を含みます。ログインに成功するには、これをPHPコードに渡します。

EDIT:コメントの新しい情報 $ _POSTデータは使用していません。カールコードで設定されていない(われわれが見ることができる)データを渡そうとしています。この置換を試してみてください:

$cookiedata = array(
    "username" => $_POST['j_username'], 
    "j_username" => $_POST['j_username'], 
    "j_password" => $_POST['j_password'] 
); 

編集:はカール更新が両方

+0

確かに私はそれを渡します...しかし、失敗 – kenwarr

+0

まだあなたのJavaScriptコードが必要です。それはあなたのデータをPHPに渡します。 –

+0

正確にはどういう意味ですか?それは私のサーバーではない...何のJavaScriptコードですか? – kenwarr

0

を使用することになりますので、ごクロム、両方のユーザ名フィールドを追加した答えは次のとおりです。

あなたは「リクエストをチェックすると、より良いです正確な要求をエミュレートするために、ブラウザによって「ヘッダ」を使用します。そう

この場合のContent-Typeアプリケーション/ x-www-form-urlencodedでなければならない

curl_setopt ($ch, CURLOPT_POSTFIELDS, $cookiedata);が良好でありません。

は、以下を行う必要があります。

curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($cookiedata)); 
関連する問題