两种方式,看服务器是否支持.1  http://user:pass@domain/cgi....2 发送 Authorization 头   'Authorization: Basic '+ base64 encode ('user:pass')以 2 为通用.

解决方案 »

  1.   


    function download_from_url($url, $proxy="", $post_data="", $cookie="", $file_name="", $http_user="", $http_pass="", $http_refer="")
    {
    $url = str_replace(" ", "%20", $url);
    $TheURL_header = substr($url, 0, 7);
    if($TheURL_header == "http://")
    {
    $pos = strpos($url, "/", 7);
    if($pos)
    {
    $host = substr($url, 7, $pos - 7);
    }
    else
    {
    $host = substr($url, 7);
    }
    $referer = "http://".$host."/";
    }
    else if($TheURL_header == "https:/")
    {
    $pos = strpos($url, "/", 8);
    if($pos)
    {
    $host = substr($url, 8, $pos - 8);
    }
    else
    {
    $host = substr($url, 8);
    }
    $referer = "https://".$host."/";
    }
    else
    {
    $pos = strpos($url, "/");
    if($pos)
    {
    $host = substr($url, 0, $pos);
    }
    else
    {
    $host = substr($url, 0);
    }
    $url = "http://".$url;
    $referer = "http://".$host."/";
    }
    if(!empty($http_refer))
    {
    $referer = $http_refer;
    }
    $c = curl_init();
    $curl_header = array(
    'Accept: */*',
    'Referer: ' . $referer,
    'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
    'Host: ' . $host,
    'Connection: Keep-Alive');
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($c, CURLOPT_HTTPHEADER, $curl_header); if(!empty($file_name))
    {
    $fp = fopen($file_name, "w");
    curl_setopt($c, CURLOPT_FILE, $fp);
    }
    else
    {
    curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($c, CURLOPT_TIMEOUT, 30);
    }
    if(!empty($cookie))
    {
    curl_setopt($c, CURLOPT_COOKIE, $cookie);
    }
    if(!empty($proxy))
    {
    curl_setopt($c, CURLOPT_PROXY, $proxy);
    }
    if(!empty($post_data))
    {
    curl_setopt($c, CURLOPT_POST, 1);
    curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
    }
    if(!empty($http_user))
    {
    //---- HTTP 用户验证 ----
    curl_setopt($c, CURLOPT_USERPWD, $http_user.":".$http_pass);
    }
    curl_setopt($c, CURLOPT_HEADER, 0);
    $res = curl_exec($c);
    $errno = curl_errno($c);
    $info = curl_getinfo($c);
    curl_close($c);
    if($fp)
    {
    fclose($fp);
    }
    return $res;
    }//...
    download_from_url("http://www.xxx.com/", "", "", "", "", $user, $pass);
      

  2.   

    谢谢 LS两位 :)1     http://user:pass@domain/cgi.... 
    -----
    通过这种方式已经解决问题