PHP cURL代理WITH头? [英] PHP cURL proxy WITH header?

查看:265
本文介绍了PHP cURL代理WITH头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个PHP图片代理脚本。我需要它,不仅回应其请求的图像的内容,而且相同地再现图像请求的头。

I'm making a PHP image proxy script. I need it to not only echo the contents of the image it requests, but also identically reproduce the header of the image request.

我看到一个,而另一个,但不是两个在一起...和这些cURL选项的东西让我困惑。

I've seen one, and the other, but not both together... and these cURL option things confuse me. How would I do this?

推荐答案

对不起,我不知道你想要什么。

Sorry, I'm not sure what is you want.

这是从图片网址,echo标头中获取并将图片保存到文件的示例。

This is the example to get from a image url, echo header and save image to a file.

但是,如果你想要一个代理,你应该使用web服务器(Nginx,Apache等),PHP是不需要

But, if you want a proxy, you should use web server (Nginx, Apache, etc), PHP is no need

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://img3.cache.netease.com/www/logo/logo_png.png");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.163.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);

list($header, $image) = explode("\r\n\r\n", $return, 2);

echo $header;

file_put_contents("/tmp/logo.png", $image);

这篇关于PHP cURL代理WITH头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆