curl을 통한 로그인 후 필요한 페이지 수집하는 function이 있던데...

curl을 통한 로그인 후 필요한 페이지 수집하는 function이 있던데...

QA

curl을 통한 로그인 후 필요한 페이지 수집하는 function이 있던데...

본문

서핑하다가 찾았는데요 간단하게 아래와 같이 설명되어있구요

 

curl로 로그인 후에 그 정보를 파일로 저장하고 로그인 뒷단에 있는 마이페이지 같은 것을

curl로 가져올때 앞에서 생성한 파일을 같이 넘겨줘서처리하는 방식입니다.

2개의 함수로 되어 있습니다.

로그인정보 저장경로는 아무나 쓰기 가능하도록 퍼미션 주셔야 합니다.

 

 

 

로그인 주소, 로그인 후 스크랩할 주소, 아이디/패스워드 입력 후  scrap 함수를 실행하면 아래와 같이 

나오는데요 어떻게 해야하는건지??

Fatal error: Using $this when not in object context in /public_html/curl.php on line 11

 

 $cookieFile = $this->auth_site_cookie_store($loginurl,$postfields);



<?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;
}
?>

이 질문에 댓글 쓰기 :

답변을 작성하시기 전에 로그인 해주세요.
전체 168
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT