2014-06-06 3 views
-1

PHP의 https 로그인 페이지로 .asp 사이트에 로그인하려고합니다. 사이트에 로그인 할 수 없습니다. 거기 dosen't 생성 된 쿠키, viewstate, 것 및 이러한 매개 변수를 밖으로 작동하는 작동하지 않는 것. 양식 필드가 올바르게 채워진 것 같습니다 (실제로 물리적으로 로그인 이름을 볼 수는 있지만) 암호 유형 인 암호 필드는 확실하지 않지만 거기에 문제가 있다고 생각하지 않습니다. 그 철자가 정확합니다.Https asp 페이지 curl login

http://www.mishainthecloud.com/2009/12/screen-scraping-aspnet-application-in.html?showComment=1368565341638#c9104469935977149435

내 코드가 아래에 있으며 최종 호출에서 "찾을 수 없음"(내 생각에는 오류 코드 7)이 반환됩니다. 첫 번째 두 건의 통화에 말림 오류가 없습니다.

사람이 함께 도와 드릴까요?

$ckfile = tempnam ("/tmp", "CURLCOOKIE"); 

// URL to login page 
$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 

// Get Login page and its cookies/ viewstate , etc 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
//curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // no cookie stored 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
$output = curl_exec($ch); 
//print(esc_html($output)); 

$viewstate = regexExtract($output,$regexViewstate,$regs,1); 
$eventval = regexExtract($output, $regexEventVal,$regs,1); 

// rebuild post info -- view state and eventvalidate empty! cant find on page 
$fields_string = 
'__VIEWSTATE='.rawurlencode($viewstate). 
'&__EVENTVALIDATION='.rawurlencode($eventval). 
'&login='.urlencode('[email protected]'). 
'&password='.urlencode('xxxx'). 
'&submit='.urlencode('Sign in'). 
'&redirect='; 

echo $fields_string; 

// Post login form -- password field ok? 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 5); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Tells cURL to follow redirects 
$outputb = curl_exec($ch); 
print curl_error; 
//var_dump($outputb); 


$url = "https://secure2.clubwise.com/glenview/bookclass.asp"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); 
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$outputc = curl_exec($ch); 
print curl_error; 
var_dump($outputc); 

헤더 정보 :

//$header= array(
//'HTTP/1.1 200 OK', 
//'Date: Mon, 09 Jun 2014 00:55:17', 
//'GMT Server: Microsoft-IIS/6.0', 
//'X-Powered-By: ASP.NET', 
//'Content-Length: 21035', 
//'Content-Type: text/html', 
//'Set-Cookie: ASPSESSIONIDCCSBSTDC=IHJBDOOBIDMJDDOFLAOOBENL; path=/', 
//'Cache-control: private' 

//); 

용액 : 그것은이 침입 일으키는 각 작업에() curl_init 하였다. Viewstate, 헤더가 필요하지 않습니다.

$ourFileName = get_stylesheet_directory()."/cookieFile.txt"; 
$ckfile = $ourFileName; 

// URL to login page 
$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // Stores cookies in the temp file 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 

$output = curl_exec($ch); 

//Cookie obtained, login 
$fields_string = 
'&redirect='. 
'&login='.urlencode('[email protected]'). 
'&password='.urlencode('xxx'). 
'&submit='.urlencode('"Sign in"') 
; 

//cookie in the header + header not required 
/* 
$cookielines =file($ckfile); 
foreach($cookielines as $row) { 
if($row[0] != '#') { 
    $cookie=$row; 
    } 
} 


$header= array(// not needed at moment 

'HTTP/1.1 200 OK', 
'Date: Mon, 09 Jun 2014 00:55:17', 
'GMT Server: Microsoft-IIS/6.0', 
'X-Powered-By: ASP.NET', 
'Content-Length: 21035', 
'Content-Type: text/html', 
'Set-Cookie: $cookie; path=/', 
'Cache-control: private' 

); 

*/ 

$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 4); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Tells cURL to follow redirects 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_ENCODING,""); 
curl_setopt($ch, CURLOPT_REFERER,"https://secure2.clubwise.com/glenview/memberlogin.asp"); 
$outputb = curl_exec($ch); 

$err = curl_errno ($ch); echo "<br>error=".$err; 
$errmsg = curl_error ($ch); echo "<br>errmsg=".$errmsg; 
$header = curl_getinfo ($ch); echo "<br>header="; var_dump($header); 
$httpCode = curl_getinfo ($ch, CURLINFO_HTTP_CODE); echo "<br>httpcode=".$httpCode; 

print curl_error; 

// 이제 당신은 각 통화에 대한 쿠키를 포함하여 암호 제한 지역 내의 모든 페이지에 액세스 할 수 있어야합니다 :

$url = "https://secure2.clubwise.com/glenview/bookclass.asp?Mode=Area&RecId=67"; 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 0); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$outputc = curl_exec($ch); 
print curl_error; 

var_dump($outputc); 
+0

'$ fields'는'count ($ fields)'에 정의되어 있지 않으므로'count ($ fields)'를'5'로 바꾸어보십시오. – FuzzyTree

+0

아니요, 불행히도 제가 배열을 사용하여 쿼리 문자열을 만들지 않았습니다. 같은 방식으로 따라서 typo :(. 당신 chrome 또는 firebug를 사용하여 viewstate/eventvalidation을 찾을 수있는 경우 알지? 난 그것에 익숙하지 않은 ASP ASP를 사용하지 마십시오. – David

+0

그냥 팁 : 나는 Pragme 같은 일반적인 브라우저 헤더를 볼 수 없어, – Sesertin

답변

1

다시 첫 번째 페이지에 저장된 쿠키를 확인하시기 바랍니다. 세션 쿠키는 CURLOPT_COOKIEFILECURLOPT_COOKIEJAR으로 설정하고 세션을 저장하려면 다시 채우거나 닫지 말아야합니다. CURLOPT_REFERER으로 설정하면 일부 사이트에서 로그인 페이지를 확인합니다.

+0

그게 다야 !! 문제가 된 각 작업에 대한 curl_init이었습니다. 감사합니다. – David