php file_get_contents curl发送cookie,使用代理
$auth = base64_encode("LOGIN:PASSWORD");//LOGIN:PASSWORD 这里是你的账户名及密码
$aContext = array(
"http" => array(
"proxy" => "tcp://192.168.0.2:3128",//这里设置你要使用的代理ip及端口号
"request_fulluri" => true,
"header" => "Proxy-Authorization: Basic $auth",
),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents(http://www.phpfensi.com, False, $cxContext);
echo $sFile;
<?php
function curl($url)
{
$str_url = $url;
$ch_curl = curl_init ();
curl_setopt ( $ch_curl, CURLOPT_TIMEOUT, 3 );
curl_setopt ( $ch_curl, CURLOPT_HEADER, false );
curl_setopt ( $ch_curl, CURLOPT_HTTPGET, 1 );
curl_setopt ( $ch_curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch_curl, CURLOPT_URL, $str_url );
//HTTP的代理
$proxy="192.168.168.251:80";
curl_setopt($ch_curl, CURLOPT_HTTPPROXYTUNNEL,true);
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
curl_setopt($ch_curl, CURLOPT_PROXY, $proxy);
//curl_setopt($ch_curl, CURLOPT_PROXYUSERPWD, "");
/*
//Sock 4 的代理
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,4);
//Sock 5 的代理
curl_setopt($ch_curl, CURLOPT_PROXYTYPE,5);
*/
$str_return = curl_exec ( $ch_curl );
if ($str_return === false)
{
return false;
}
curl_close ( $ch_curl );
return $str_return;
}
$url = "http://p1.img.cctvpic.com/xiyou/userimage/2012/10/18/163312135054919266639.jpg";
$contents = curl($url);
var_dump($contents);
file_put_contents("/tmp/1p.jpg",$contents);
?>声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
