用户反馈分享海报插件无法生成问题,查询原因:用户引用的外链图片地址设置了防采集
解决方法:
伪造curl 伪装来路(referer)
<?php $url = $_GET['sharePicurl']; $dir = pathinfo($url); $host = $dir['dirname']; $refer = $host.'/'; $ajax = Network::Create(); $ajax->open('GET', $url); $ajax->enableGzip(); $ajax->setTimeOuts(120, 120, 0, 0); $ajax->setRequestHeader('referer', $host); $ajax->send(); $ext = strtolower(substr(strrchr($url,'.'),1,10)); $types = array( 'gif'=>'image/gif', 'jpeg'=>'image/jpeg', 'jpg'=>'image/jpeg', 'jpe'=>'image/jpeg', 'png'=>'image/png', ); $type = $types[$ext] ? $types[$ext] : 'image/jpeg'; header("Content-Type:".$type); echo $ajax->responseText;
其他PHP(以上方法仅适用zblog)
<?php $url = $_GET["imgurl"]; $dir = pathinfo($url); $host = $dir['dirname']; $refer = $host.'/'; $ch = curl_init($url); curl_setopt ($ch, CURLOPT_REFERER, $refer); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); $ext = strtolower(substr(strrchr($url,'.'),1,10)); $types = array( 'gif'=>'image/gif', 'jpeg'=>'image/jpeg', 'jpg'=>'image/jpeg', 'jpe'=>'image/jpeg', 'png'=>'image/png', ); $type = $types[$ext] ? $types[$ext] : 'image/jpeg'; header("Content-type: ".$type); echo $data;
好了,以上就是php绕过图片防盗链的方法全部方法,更多php教程zblog教程关注菜鸟建站。
发表评论