질문Q #16870
curl 초보입니다 ㅠ 로그인 후 화면 보이기 질문...
neo천2017-02-21 17:06:21

https://www.getresponse.kr/?_ga=1.17986928.839957066.1487571930

 

위의 사이트를 curl 이용하여 로그인 후  메인화면을 보고 싶어서 작업하였습니다.

 

처음이라 여러 예제를 다써보았는데 잘안됩니다ㅠㅠ

 

사용한 코드입니다.

 

로그인시)

$url = "https://app.getresponse.com/login.html?lang=ko&_ga=1.149318966.1406336218.1487585818";

$post_data = array( "login"=>'아이디' ,"password"=>'비번');

$cookie_nm = tempnam("/tmp/cookie.txt", "COOKIE");

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt ($ch, CURLOPT_SSLVERSION, 0);  

curl_setopt ($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_nm); 

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_nm); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); 

$result = curl_exec($ch);

 

 

로그인 후 가져올 화면)

$url = "https://app.getresponse.com/main.html";

$ch = curl_init ();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_nm);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, FALSE); 

$result = curl_exec ($ch); 

 

echo "result : ".$result."<br>";

echo 'Curl error: ' . curl_error($ch); 

curl_close($ch);

 

위예제를 사이트 주소랑, $post_data만 바꿔서 제가 만든 간단한 사이트에서는 로그인 후 잘가져옵니다..

 

 

1. 로그인시 curl설정이 싸이트마다 달라지는지..궁금합니다.

 

2. 그리고 예시코드중에 잘못된 부분이 있는지...ㅠㅠ

 

몇시간째 헤매고있습니다. 도움좀 부탁드리겠습니다!

답변1
#1 변종원(웅파) 2017-02-22 17:38:56

로그인은 되는건가요? 

비정상 접근을 막기 위해 다른 값을 저장할 수도 있습니다. csrf 막는게 적용되어 있을 수도 있구요.