1
저는 새로운 말풍선이며 많은 자습서를 사용해 보았습니다. 내가 만든 마지막 시도가 다음 코드를 사용했다 : Curl을 사용하여 웹 사이트에 로그인하려고 시도했습니다.
<?php
// INIT CURL
$url="http://www.justanswer.com/account/sign-in.aspx";
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=.*?;.*?)\n#";
preg_match_all($pattern, $result, $matches);
array_shift($matches);
$cookie = implode("\n", $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, "http://www.justanswer.com");
// Print the output
print curl_exec($page);
?>
누군가가 내가 잘못 뭐하는 거지 설명 할 수 제발, 나는 파이어 폭스에서 라이브 HTTP 헤더 확장을 사용하여 동일한 POST 요청을 복제하고 그것을 성공했습니다.
http://www.justanswer.com/login.aspx
TIA을 제안하십시오에서
로그인 페이지입니다
코드? –