php如何用代理访问网站 以及图片防盗链代理服务器

2018-10-10 10:11:43


代理访问网页

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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。


  • 2019-10-11 13:48:00

    关于Integer比较相等的问题

    原来两个Integer类型的数字不能用==来判断,要用equal 不过Integer类型的可以与1,2这样的纯数字来判断

  • 2019-10-14 21:18:57

    Comparable 的 使用

    要做这个呢,我们也是用到了Arrays.sort 这个排序的方法!但不同的是,我们之前用的是int数组,现在我们用的是这个UserBean数组。如果你想对这个UserBean数组进行排序,你要多做一件事,就是让这个 UserBean类去 实现Comparable 的接口,并重写 里面  comparaTo 的方法。注意,这个接口是可以提供泛型的 ———————————————— 版权声明:本文为CSDN博主「sdn_bt496」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明