로그인 주소는 빼고 공개를 합니다. (주소는 알아서 찾으세요)
curl로 로그인 후에 그 정보를 파일로 저장하고
로그인 뒷단에 있는 마이페이지 같은 것을 curl로 가져올때 앞에서 생성한 파일을 같이 넘겨줘서
처리하는 방식입니다.
2개의 함수로 되어 있습니다.
소스는 간단하니 따로 설명은 안하겠습니다.
유용하게 쓰시길..... (원 소스는 구글 검색해서 찾은 건데 어느 분 것인지 모르겠네요)
로그인정보 저장경로는 아무나 쓰기 가능하도록 퍼미션 주셔야 합니다.
<?php
function scrap()
{
$geturl="로그인후 스크랩할 주소";
$loginurl = '로그인 주소';
$postfields = 'id=아이디&password=비밀번호';
$cookieFile = $this->auth_site_cookie_store($loginurl,$postfields);
echo $result = $this->auth_site_get($geturl, "/저장경로/".$cookieFile, $postfields);
}
function auth_site_cookie_store($loginurl, $postfields)
{
$parseURL = parse_url($loginurl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$loginurl");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/저장경로/".$parseURL['host'].".cookie");
ob_start();
curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
return $parseURL['host'].".cookie";
}
function auth_site_get($geturl, $cookiefile, $postfields)
{
$parseURL = parse_url($geturl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1 );
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,100);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/저장경로/".$parseURL['host'].".cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "$cookiefile");
curl_setopt($ch, CURLOPT_URL,"$geturl");
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
?>