2017-02-03 8 views
2

私はbukalapak.comでログインするためにカールを使用しています。 しかし、常にリダイレクトされています&私はそれを解決するカールfollowlocationを使用するが、なぜリダイレクト後にログインしていないのですか? ログインする、&おかげで最初bukalapak.comログインphp curlを使用して

<?php 
 
function curl($url, $post){ 
 
$curl = curl_init(); 
 
curl_setopt_array($curl, 
 
array(CURLOPT_URL => $url, //put your url here 
 
CURLOPT_SSL_VERIFYPEER => false, 
 
CURLOPT_SSL_VERIFYHOST => false, 
 
CURLOPT_RETURNTRANSFER => true, 
 
//CURLOPT_ENCODING => "", 
 
CURLOPT_POSTREDIR => 3, 
 
CURLOPT_HEADER => true, 
 
//CURLOPT_MAXREDIRS => 10, 
 
//CURLOPT_TIMEOUT => 30, 
 
//CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
 
CURLOPT_CUSTOMREQUEST => "GET", 
 
CURLOPT_POST => true, 
 
CURLOPT_FOLLOWLOCATION => false, 
 
CURLOPT_COOKIEFILE => "cookie.txt", 
 
CURLOPT_COOKIEJAR => "cookie.txt", 
 
CURLOPT_POSTFIELDS => $post, 
 
CURLOPT_HTTPHEADER => array(
 
"cache-control: no-cache", 
 
"Content-type: text/html; charset=UTF-8" 
 
), 
 
)); 
 

 
$response = curl_exec($curl); 
 
$info = curl_getinfo($curl); 
 
$err = curl_error($curl); 
 
curl_close($curl); 
 
return $response; 
 
} 
 

 
$p = array(
 
"user_session[username]"=>"[email protected]", 
 
"user_session[password]"=>"Blablabla", 
 
"commit"=>"Login", 
 
"comeback"=>"%2F" 
 
); 
 

 
$login = curl("https://www.bukalapak.com/user_sessions", http_build_query($p)); 
 

 
echo $login; 
 
?>

HTTP/1.1 302 Found Server: nginx Date: Fri, 03 Feb 2017 06:28:03 GMT Content-Type: text/html; charset=utf-8 Location: https://www.bukalapak.com/ Transfer-Encoding: chunked Connection: keep-alive Status: 302 Found Cache-Control: max-age=0, private, must-revalidate, no-transform X-We-Need-To-Talk: Hey, you need to check out https://www.bukalapak.com/careers :) Vary: Origin X-Permitted-Cross-Domain-Policies: none X-XSS-Protection: 1; mode=block X-Request-Id: 90f9ca9a-4ade-4c3d-a0ea-592effd5c2ee X-Download-Options: noopen X-Found-Something: Found any vulnerabilities in our system? https://www.bukalapak.com/bug_reports X-Frame-Options: SAMEORIGIN X-Content-Type-Options: nosniff Set-Cookie: _mkra_ctxt=8891a37006424c9c608a41bf3f6558de--302; path=/; max-age=5; HttpOnly Set-Cookie: lskjfewjrh34ghj23brjh234=RjhGMUlkUEpHb0NOaTNLeUFoT2x2RmxZeWxDTWRySEV6aUc4a0tBOWhqbGdZVS9kWUlOZHFOSXNVZWt2UmJCTkFBRXZLVW8wd21rUktrYXZQR05lUU01aHRuemdzVi91WnFqcUFid2s0MVhUbGhmQXk0cGIrVU5iaXR3UW1HQ21LeHJHRHhMRGZucGo3UUluZ2FLbjJMSWZiZVExODgyRmtUQXJaMTZjYVQxMXZSOWg5U3FGeHZZTGdxVllNTFp4MGtDcnJiaEEwL0NkTVNNT2lTWE8yQXNtNEIzWTVKc0h4NVdVeEVKYnZMSVFMQ29KcysyUGdnK2VZaWNLaVozL3NXYzVIcXlHWkY4SDZESjF4RXp6ak5wVXVOeXRXdjZ0YkZ1UWhPQVJNcjA9LS1od2k3aTgzM3pBSEx5TDVqcE9ZWUZ3PT0%3D--0f995ca0f739bbb3f94b4e92b6628da326a2cb5c; domain=.bukalapak.com; path=/; HttpOnly Strict-Transport-Security: max-age=31536000; includeSubdomains You are being redirected.

答えて

0

オフの前に私を助けて、あなたは、有効なクッキーのセッションIDと "authenticity_token" コンボを必要としています。各クッキーセッションには固有のauthenticity_tokenがあり、正しい1を送信しないとログインできません。

あなたのコードはauthenticity_tokenを取得しようとしません。

ログインパラメータが不足しているため、ログインが不可能になる可能性があります。いくつか、utf8comebackab_keep_logincommitに言及(そしてより多くのがあります)

また、あなたのコードの使用をmultipart/form-dataエンコーディングが、ウェブサイトの使用application/x-www-form-urlencodedエンコーディングを、なるように修正(有効なX-WWW-を生成するhttp_build_queryを使用しますform-urlencodedで文字列)

最初のログインページにGETリクエストを行い、クッキーが有効になっていることを確認し、ログイン要求(ただし、警告属するすべての<input>のタグを解析、<input>を含むHTMLでのいくつかの形式がありますタグの場合は、ログインフォーム(別名id new_user_session)に属する入力のみ、その名前と値が必要です(DOMDユーザー名/パスワード変数を変更し、これらすべてのタグを使用してログインPOSTリクエストを送信し、実際のブラウザと同様にと同じようにapplication/x-www-form-urlencodedエンコーディングを使用するようにしてください。 https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.phpからhhb_curlを使用して

は、ここでの例です(それが動作するはずです、実際のユーザ名/パスワードを提供)

<?php 
declare(strict_types = 1); 
require_once ('hhb_.inc.php'); 
$hc = new hhb_curl(); 
$hc->_setComfortableOptions(); 
$hc->exec ('https://www.bukalapak.com/user_sessions'); 
$html = $hc->getResponseBody(); 
$domd = @DOMDocument::loadHTML ($html); 
$inputs = array(); 
foreach ($domd->getElementById ("new_user_session")->getElementsByTagName ("input") as $input) { 
    $inputs [$input->getAttribute ("name")] = $input->getAttribute ("value"); 
} 
var_dump ($inputs); 
assert (array_key_exists ('authenticity_token', $inputs)); 
$inputs ['user_session[username]'] = '[email protected]'; 
$inputs ['user_session[password]'] = 'Blablabla'; 
$hc->setopt_array (array (
     CURLOPT_POST => true, 
     CURLOPT_POSTFIELDS => http_build_query ($inputs), 
     CURLOPT_URL => 'https://www.bukalapak.com/user_sessions', 
     CURLOPT_HTTPHEADER => array (
       'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' 
     ) 
)); 
$hc->exec(); 
$html = $hc->getResponseBody(); 
hhb_var_dump ($hc->getStdErr(), $hc->getResponseBody()); 
関連する問題