PHP通过HTTP请求防盗链

anti-theft_chain.php

<?php
header("content-type:text/html;charset=utf-8");
if(isset($_SERVER['HTTP_REFERER']))
{
	//域名对比,一致下载,不一致跳转到错误页面
	//strpos: 查找字符串首次出现的位置
	if(strpos($_SERVER['HTTP_REFERER'],"http://guofeng.io")===0)
	{
		echo "您可以下载软件了";
	}else
	{
		echo "请从本网站下载";
	}
}
?>

anti-theft_chain.html

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>测试页面</title>
</head>
<body>
	<a href="http://guofeng.io/anti-theft_chain.php">测试页面</p>
</body>
</html>

Continue Reading

PHP隐藏下载地址

download.php

<?php
//获取传递的文件名
$filename = $_GET['filename'];
$pathname = "$./download/$filename";
//以只读方式打开文件
$handle = fopen($pathname,"rb");
//返回数据的内容类型
//'octet-stream'八位二进制流
//'content-desposition:attachment'以附件形式打开
header("content-type:application/octet-stream");
header("content-despositon:attachment;filename=$filename");
//循环读取指定大小的内容,并输出
while($str=fread($handle,1024))
{
echo $str;
}
//关闭文件
fclose($handle);
?>

download.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<a href="download.php?filename=test.jpg">下载图片</a>
<br>
<a href="download,php?filename=test.mp4">下载视频</a>
</body>
</html>

Continue Reading
Close Menu