curl 2
<!--
function curl($url) {
$cookieFile = tempnam(sys_get_temp_dir(), 'cookie');
$mb_id = 'rudgys';
$mb_password = '1qaz2wsx';
$RequestHeader = array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Content-Type: multipart/form-data'
);
$loginUrl = 'https://www.xxx.co.kr/bbs/login_check2020.php';
// cURL 초기화
$ch = curl_init();
// 로그인 요청 설정
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'username' => $mb_id,
'password' => $mb_password
)));
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $RequestHeader);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 로그인 요청 실행
$loginResponse = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Login cURL error: ' . curl_error($ch);
return;
}
// 데이터 요청 설정
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
// 데이터 요청 실행
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Fetch cURL error: ' . curl_error($ch);
return;
}
// 헤더와 바디 분리
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
unlink($cookieFile); // 쿠키 파일 삭제
return $body;
}