代理访问网页
function
curl_string (
$url
,
$user_agent
,
$proxy
){
$ch
= curl_init();
curl_setopt (
$ch
, CURLOPT_PROXY,
$proxy
);
curl_setopt (
$ch
, CURLOPT_URL,
$url
);
curl_setopt (
$ch
, CURLOPT_USERAGENT,
$user_agent
);
curl_setopt (
$ch
, CURLOPT_COOKIEJAR,
"c:\cookie.txt"
);
//可删除
curl_setopt (
$ch
, CURLOPT_HEADER, 1);
curl_setopt (
$ch
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt (
$ch
, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt (
$ch
, CURLOPT_TIMEOUT, 120);
$result
= curl_exec (
$ch
);
curl_close(
$ch
);
return
$result
;
}
$content
=
"http://www.google.com"
;
$user_agent
=
"Mozilla/4.0"
;
$proxy
=
"http://192.11.222.124:8000"
;
代理访问图片,解决防盗链
随着HTTPS的普吉,但是很多时候外联的图片却未开通HTTPS,那怎么办呢,我们只能做一个图片代理,来通过后台来绕过HTTPS请求HTTP图片的时候报错的麻烦
不懂curl的同学看这里
if(strstr($imgUrl,'wscgs.sxga.gov.cn')){ $url = $imgUrl; }else{ $url = "http://www.sxol.com/Images/index20120814/Logo.gif"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); curl_setopt($ch, CURLOPT_HEADER, 0); $img=curl_exec($ch); curl_close($ch); header("Content-type: image/jpg"); echo $img; 作者:ONEDAYLOG 链接:https://www.jianshu.com/p/5e8128b6ac9e 來源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。