2011-04-06 54 views
1

IM使用卷曲和PHP获得的卷曲,密码和用户名外部网页

代码retreiving网页作为一个字符串:

$ch = curl_init(); 
    // the external url 

    $url = 'http://cursos.puc.cl/eaa220a-1/correo/main.html'; 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); 
    curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
     "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" 
    )); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    // get the source code 
    $html = curl_exec($ch); 

但是网页,要求用户名和passowrd进入。我不知道如何管理这个。 Thx!

回答

2

here

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
$output = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch); 

你可以阅读更多关于curl_setopt()here

+0

我做你说的和页面加载和加载和加载...用户名和psw是正确的,因为即时通讯与我的访问。任何想法? – 2011-04-06 04:45:17

+0

你有什么错误吗? – fabrik 2011-04-06 04:47:44

+0

nvm,有一个愚蠢的扣,thx! – 2011-04-06 04:55:54