- 정보공유
[PHP] 외부에서 자동로그인
$loginUrl = 'http://도메인/bbs/login_check.php'; $login_data = array( 'mb_id' => 'admin', 'mb_password' => '비밀번호' ); $cookie_nm = "./cookie.txt"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL,$loginUrl); //접속할 URL 주소 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_SSLVERSION,1); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A', 'Referer: http://b도메인/' )); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_nm); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_nm); curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($ch); curl_setopt($ch, CURLOPT_URL,"http://도메인/bbs/board.php?bo_table=테이블코드"); //접속할 URL 주소 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_nm); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_nm); $result = curl_exec ($ch); curl_close ($ch); echo $result;
<meta charset="utf-8"> <?php include "Snoopy.class.php"; $snoopy = new Snoopy; $snoopy->referer = "b도메인"; $snoopy->agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; $snoopy->rawheaders["Pragma"] = "application/x-www-form-urlencoded"; $submit_url = "http://b도메인/bbs/login_check.php"; $submit_vars["mb_id"] = "admin"; $submit_vars["mb_password"] = "비밀번호"; $snoopy->submit($submit_url,$submit_vars); $snoopy->setcookies(); $snoopy->fetch("b도메인/게시판주소"); print $snoopy->results; ?>