php解决微信文章图片防盗链

解决微信文章图片防盗链

function actionWechatImg()
{
    header('Content-type: image/jpg');
    $url = $_GET['url'];
    $refer = "http://www.qq.com/";
    $opt = [
            'http'=>[
                'header'=>"Referer: " . $refer
            ]
           ];
    $context = stream_context_create($opt); 
    $file_contents = file_get_contents($url,false, $context);
    echo $file_contents;
}

调用示例:

<img src="http://xxx.com.cn/wechat-img?url=http%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz%2F5ddyukqqNUt7ic07NicfAz9u0KrHEibKKMiab2cXA2sIqoj81hRsMZC65DCiaN67FsH2WaXkNOEE0YFLj5OHwIOegIg%2F0%3Fwx_fmt%3Djpeg">

其实就是模拟来源站点。

原文地址:https://www.cnblogs.com/skyfynn/p/6555368.html