反代Github和jsdelivr进行加速
2023-7-14 17:13:0 Author: blog.upx8.com(查看原文) 阅读量:18 收藏

2023-07-13T12:39:11.png

使用方法

在PHP安装“fileinfo”扩展,然后在网站目录新建一个名为gh.php的文件,将下面的代码复制粘贴进去。然后访问:你的域名/gh.php?url=你要代理的URL地址

代码

<?php
if (isset($_GET['url']) == false) {
die("请将参数填写完整,在当前路径后加上?url=反代的链接");
}

$token = (string) rand(100, 99999);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if (isset($_SERVER['HTTP_REFERER']) == true) {
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
}
$data_down = curl_exec($ch);
if ($data_down === FALSE) {
die("代理时发生错误");
}
curl_close($ch);
file_put_contents($token, $data_down);

// 使用finfo扩展获取文件的MIME类型
$finfo = new finfo(FILEINFO_MIME);
$mime_type = $finfo->file($token);

header('Content-Type: ' . $mime_type);
unlink($token);
echo $data_down;
?>


文章来源: https://blog.upx8.com/3689
如有侵权请联系:admin#unsafe.sh