2010-11-30 1 views
3

저는 인터넷에서 키워드 asp login curl php .ASPXAUTH가 포함 된 모든 게시물을 준비 할 때 거의 100 % 확신합니다. 그러나 찾을 수 없습니다. 해결책. 우아한 개발자보다 코드 해커가 더 많으므로 누군가 제발 나를 도울 수 있기를 바랍니다.PHP cURL을 사용하여 로그인 할 때 .ASPXAUTH 쿠키 값을 가져올 수 없습니다.

두 개의 다른 웹 사이트에 로그인하여 로그인 뒤에서 양식을 제출하는 컬 스크립트가 있습니다. 그러나 최근에 세 번째 웹 사이트에이 스크립트의 변형을 사용하려고했습니다. 그것은 로그인까지 첫 페이지를 반환하는 것처럼 작동하지만, 로그인하지 않은 것처럼 추가 cURL 호출을 처리합니다. 설정되지 않은 .ASPXAUTH 쿠키와 관련이 있다는 것을 발견했습니다. 쿠키 목록에 cookiefile 및 cookiejar 설정이 있지만 .ASP.NET_SessionID가 성공적으로 캐치되지만 .ASPXAUTH 쿠키는 캐치되지 않습니다.

"라이브 HTTP 헤더"를 볼 때 머리글에서 .ASPXAUTH 쿠키 값을 볼 수 있지만이 쿠키로 헤더를 매우 쉽게 반환 할 수는 없습니다. 로그인 후에 쿠키가 302로 설정되고 cURL이 올바르게 처리하지 못하는 것으로 보입니다. 그래서 CURLOPT_FOLLOWLOCATION을 끄고 직접 리다이렉션을 처리하려고했으나 여전히 제대로 작동하지 않습니다 (서버가 실제로 이상한 리디렉션 URL을 반환하고이 부분을 제대로 수행하고 있다고 생각하지 않습니다)

하지만

//setup Curl 
    $cookiename = substr($from,4,5); 
    $cookiefile = $cookiename . ".txt"; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (Windows; MSIE 6.0; U; Windows NT 5.1)"); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); 

    //read login page 
    curl_setopt($ch, CURLOPT_URL, "Login.aspx"); 
    $result = curl_exec ($ch); 

    echo $result; 



    // extract values for hidden form fields __REQUESTDIGEST __VIEWSTATE __EVENTVALIDATION fields 

    //extract __REQUESTDIGEST 
    $start = strpos($result,"id=\"__REQUESTDIGEST\" value=\"") + 28; 
    $end = $start + 157; 
    $rdigest = substr($result , $start , $end - $start); 

    //extract __VIEWSTATE 
    $start = strpos($result,"id=\"__VIEWSTATE\" value=\"") + 24; 
    $end = $start + 16300; 
    $vstate = substr($result , $start , $end - $start); 
    $vstate = urlencode($vstate); 

    //extract __EVENTVALIDATION 
    $start = strpos($result,"id=\"__EVENTVALIDATION\" value=\"") + 30; 
    $end = $start + 120; 
    $event = substr($result , $start , $end - $start); 
    $event = urlencode($event); 


    //set login form values and login 

    //curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_REFERER, 'Login.aspx'); 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, '__REQUESTDIGEST=' . $rdigest . '&__VIEWSTATE=' . $vstate . '&__EVENTVALIDATION=' . $event . '&UserName=' . $from . '&Password=' . $password); 
    $result = curl_exec ($ch); 

    echo $result; 

    //extract __redirect 
    $start = strpos($result,"Location:") + 10; 
    $end = strpos($result,".aspx") +5; 
    $redirect = substr($result , $start , $end - $start); 
       $redirect = "https://www.domain.com/" . $redirect; 

    echo $redirect ."<br /><br />"; 

    echo $result; 

    curl_setopt($ch, CURLOPT_URL, $redirect); 
    $result = curl_exec ($ch); 

    echo $result; 

그리고 여기에 출력 : : 내 사용자 에이전트를 업데이트

//Login page headers 
HTTP/1.1 200 OK Date: Tue, 30 Nov 2010 12:57:09 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: no-cache Pragma: no-cache Expires: -1 Content-Type: text/html; charset=utf-8 Content-Length: 81835 
//Login page body 

Submit login page headers 
HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Tue, 30 Nov 2010 13:40:30 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Location: /(F(RZPDiDBb9OPbTuBnj2RAgH8KglRdj4B4u8trRMpa6QbBjff4evKMtHnOFNyX046Xdr33PZA3-6dHoZjxQpeZ7aNTevF75gArtpeScCjE9fI1))/default.aspx Set-Cookie: ASP.NET_SessionId=bhugr045cyybck45xvhpeb55; path=/; HttpOnly Cache-Control: no-cache Pragma: no-cache Expires: -1 Content-Type: text/html; charset=utf-8 Content-Length: 82196 


//Redirect page body 

//The login page body is displayed again 

//More headers 
HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Date: Tue, 30 Nov 2010 13:29:05 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 3026 

//Error message from server 
Server Error in '/' Application. 
Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

답변

1

나는 여기

내 코드는 ... 누군가가 나를 도와주세요 수 있다면 매우 감사하게 될 것입니다 이것에

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (Windows; MSIE 6.0; U; Windows NT 5.1)"); 

:

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)"); 
쿠키 파일 :에서 다른 사용자 에이전트 라인과 갑자기 .ASPXAUTH 쿠키가 (자동으로) 제대로 설정은 otherwords에서

나는이 줄을 변경

이제 두 가지 쿠키가 모두 자동으로 설정됩니다. 아무런 문제가 없습니다.

만세!

+0

나는 같은 문제가있다. 나는 여기서 쓴 것을 시도했지만 도움이되지 않는다. 그것은 과거에 일했습니다. 흥미로운 것은 여전히 ​​wget과 작동합니다. wget으로 aspxauth 쿠키를 얻습니다. – Adrian

+0

몇 가지 다른 사용자 에이전트 문자열을 사용해 보셨습니까? 현재 브라우저와 동일한 사용자 에이전트 문자열을 사용하고 위에 나열된 사용자 에이전트 문자열을 사용하지 마십시오. 위 예제의 사용자 에이전트는 꽤 오래되었습니다. – richelectron

관련 문제