프로그램/PHP
[PHP]cURL로 웹페이지 가져오기
주원대디
2014. 7. 18. 17:49
[PHP]cURL로 웹페이지 가져오기 |
function get_curl($url) { $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'; $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POST, 0); curl_setopt ($ch, CURLOPT_USERAGENT, $agent); curl_setopt ($ch, CURLOPT_REFERER, ""); curl_setopt ($ch, CURLOPT_TIMEOUT, 3); $buffer = curl_exec ($ch); $cinfo = curl_getinfo($ch); curl_close($ch); if ($cinfo['http_code'] != 200) { return ""; } return $buffer; } $url ="";//가져올 URL 주소 echo $buffer = get_curl($url); ?>