这篇文章主要介绍了php简单防盗链实现方法,涉及php针对服务器端预定义变量调用及字符串处理的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
具体如下:
<?php
$ADMIN = array(
'defaulturl'=> 'http://blog.qita.in/images/banner-header.gif',
//盗链返回的地址
'url_1' => 'http://blog.qita.in/file',
'url_2' => 'http://blog.qita.in/file1',
);
$okaysites = array(
'http://qita.in',
'http://blog.qita.in', //白名单
'http://blog.qita.in/1.html',
);
$reffer = $_SERVER['HTTP_REFERER'];
if ($reffer) {
$yes = 0;
while (list($domain, $subarray) = each($okaysites)) {
if (ereg($subarray, "$reffer")) {
$yes = 1;
}
}
$theu = 'url_' . $_GET['site'];
$file = $_GET['file'];
if ($ADMIN[$theu] and $yes == 1) {
header("Location: $ADMIN[$theu]/$file");
} else {
header("Location: $ADMIN[defaulturl]");
}
} else {
header("Location: $ADMIN[defaulturl]");
}
print_r($_SERVER['HTTP_REFERER']);
?>总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是php针对服务器端预定义变量调用及字符串处理的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号