PHP如何连“http基础验证(http basic authentication)”?谢谢 两种方式,看服务器是否支持.1 http://user:pass@domain/cgi....2 发送 Authorization 头 'Authorization: Basic '+ base64 encode ('user:pass')以 2 为通用. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); 谢谢 LS两位 :)1 http://user:pass@domain/cgi.... -----通过这种方式已经解决问题 php如何打印页面并判断是否打印成功(打印机),我用window.print()!但是这个函数没有返回值 谁能告诉我这样的样式用什么用的! phpeclipse PHPWIND论坛:帖内字符串替换,正则表达式 php curl 如何抓去页面 请问jquery如何删除当前列? 关于session_start();的错误?怎么回事? VxWorks上的web开发,有没有类似于php之类的脚本语言 哪位晓得大型网站信息采编系统的技术内幕? session使用前是不是还要对其进行某些配置呀,怎么配 请问!WYSIWYG编辑器问题!! 求助zend 上CVS的使用(windows)
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);
-----
通过这种方式已经解决问题