[苹果cms]图片防盗链代码

这是经过 AI 调整优化过后的代码,在苹果CMS后台找到 系统 > 附件参数配置 > 反盗链接口,将文件命名为 img.php 并放在网站根目录,反盗链接口预设为 /img.php?url=

<?php
error_reporting(E_ERROR | E_PARSE );
@ini_set('max_execution_time', '0');
@ini_set("memory_limit",'-1');
$url = $_GET["url"];
if (!empty($url) && substr($url,0,4)=='http') {
    $dir = pathinfo($url);
    $host = $dir['dirname'];
    $ext = $dir['extension'];
    $refer = $host.'/';
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_REFERER, $refer);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HEADER,0);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $data = @curl_exec($ch);
    curl_close($ch);
    $types = array(
        'gif'=>'image/gif',
        'jpeg'=>'image/jpeg',
        'jpg'=>'image/jpeg',
        'jpe'=>'image/jpeg',
        'png'=>'image/png',
        'webp'=>'image/webp',
    );
    $type = $types[$ext] ? $types[$ext] : 'image/jpeg';
    header("Content-type: ".$type);
    echo $data;
}
READ  [苹果cms] 优化截图标签模块
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《[苹果cms]图片防盗链代码》
文章链接:https://www.rank50.com/technique/3029.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册