English 中文(简体)
利用库勒将伐木制作成一个网站
原标题:Trying to logging into a website using Curl

我是新鲜的,经过了许多辅导。 我最后试图使用以下法典:

<?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

问题回答

总结作为阵列的形式变量,例如:

$postVars = array("__EVENTTARGET"   => "",
                  "__EVENTARGUMENT" => "",
                  "__SSVIEWSTATE"   => "18",
                  "__VIEWSTATE"     => "",
                  "email"           => "****",
                  "sign_in_type"    => "returning"
                  "foo" => "bar");




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签