$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);
?>

php file_get_contents curl发送cookie,使用代理的更多相关文章

  1. PHP下通过file_get_contents\curl的方法实现获取远程网页内容(别忘了还有PhpRPC)

    [php]PHP中file_get_contents()与file_put_contents()函数细节详解 php函数file_get_contents(一) 案例: 早在2010年时候遇到过这样的 ...

  2. 使用curl传递cookie错误的问题

    工作中发现一个问题, 通过curl调用接口传递cookie操作用户的数据, 接口的程序解析不了cookie中的数据. 经过排查发现curl发送的cookie数据为 TZ+Gn+rEk+6G4d 而接口 ...

  3. 简单设置,解决使用webpack前后端跨域发送cookie的问题

    最近用vue来做项目,用webpack来做前端自动化构建.webpack-dev-server会在本地搭建一个服务器,在和后端调试的时候,就会涉及到跨域的问题. 刚开始时,没有用vue-cli来构建项 ...

  4. windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因

    这两天一直在搞windows下nginx+fastcgi的file_get_contents请求.我想,很多同学都遇到当file_get_contents请求外网的http/https的php文件时毫 ...

  5. php使用curl带cookie访问一直失败求助

    最近需要批量向织梦后台导入一些数据,但是遇到了一个头疼的问题. 环境:xampp + 别人的dede后台. 首先,利用curl发送post请求登录login.php,成功,并且保存了cookie文件. ...

  6. php通过curl发送XML数据,并获取XML数据

    php编程中经常会用到用xml格式传送数据,如调用微信等第三方接口经常用到,这里演示下php以curl形式发送xml,并通过服务器接收 一.发送xml数据 -- postXml.php <?ph ...

  7. 跨域问题,前端主动向后台发送cookie

    跨域是什么? 从一个域名的网页访问另一个域名的资源,就会出现跨域.只要协议.端口.域名有一个不同就会出现跨域 例如: 1.协议不同  http://www.baidu.com:80 和 https:/ ...

  8. curl发送请求时携带cookie-转载未验证

    <?php header('Content-Type:text/html;charset=utf-8'); echo "<pre>"; function curl ...

  9. Android端接收和发送cookie

    流程: 首先android端使用HttpClient的方式发送HTTP请求,此时服务器创立cookie,并发送cookie给android端,android端再将cookie保存起来,在需要发送coo ...

随机推荐

  1. iOS 设置button中图文位置

    方法一. -(CGRect)imageRectForContentRect:(CGRect)contentRect {    return CGRectMake(self.width - kImage ...

  2. 专题实验 PGA

    PGA : 是完全为 server process 服务的, 在 server process 创建时被分配到, 在server process 终止时被释放. 而且是非共享的, 只独立服务于这个se ...

  3. Git基本交互流程图

  4. Sqlserver_判断该路径是否存在该文件

    declare @result int =0declare @path nvarchar(200)='d:\1.csv'execute master.dbo.xp_fileexist @path ,@ ...

  5. 不能上传文件 unknown error happened

    做一件事情: 1 找出问题,发现问题,2 搜索问题,3 找到答案,验证之.4 找不到答案,想出思路,验证....5 不断想,记录笔记.

  6. BOM头的来源

    类似WINDOWS自带的记事本等软件,在保存一个以UTF-8编码的文件时,会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM).它是一串隐藏的字符,用于让记事本等编辑器识别 ...

  7. OpenCV3编程入门笔记(2)计时函数、感兴趣区域RIO、分离/混合通道

    11     绘制直线的line函数 DrawLine(Mat img, Pont start, Point end); 绘制椭圆的ellipse函数 DrawEllipse(Mat img, dou ...

  8. 自定义 密码是否可见 的EditView 右侧带个小眼睛

    package com.qyk.douban.widget; import android.content.Context; import android.text.Editable; import ...

  9. 晒幸福, qq空间晒法

    qq空间晒法 1.成为老婆之后,还是说新交的女朋友,这会让女朋友感动

  10. OneProxy主从延迟检测

    OneProxy具有主从延迟检测功能,检测方式有两种. 1.通过MySQL本身提供的延迟信息,即在从库中执行show slave status; 查看Seconds_Behind_Master值: 2 ...