Home > Backend Development > PHP Tutorial > php获取浏览器地址然后防盗链,刷新后便获取不到地址,请教是咋回事

php获取浏览器地址然后防盗链,刷新后便获取不到地址,请教是咋回事

WBOY
Release: 2016-06-13 12:41:33
Original
828 people have browsed it

php获取浏览器地址然后防盗链,刷新后便获取不到地址,请问是怎么回事啊
 
我的x.php代码如下。这个代码的大概意思是:我用一个网站引用另外一个网站的资源。
我的网站是http://www.123.com 和 http://www.abc.com
如果我输入http://www.123.com/x.php/love.mp3,实际上打开的是
http://www.abc.com/abc/love.mp3。下面代码完全可以实现了。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 header("content-Type: text/html; charset=Utf-8");
 $SERVER=$_SERVER["REQUEST_URI"];
 preg_match("/php\/([\s\S]+)\.mp3/",$SERVER,$url);
 $urlname=$url[1];
 $downurl='http://www.abc.com/abc/'.$urlname.'.mp3';
 header("location:$downurl");
 ?>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
网页中的播放器可以正常播放http://www.123.com/x.php/love.mp3
后来我加入了防盗链,防下载,代码:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 header("content-Type: text/html; charset=Utf-8");
 $SERVER=$_SERVER["REQUEST_URI"];
 preg_match("/php\/([\s\S]+)\.mp3/",$SERVER,$url);
 $urlname=$url[1];
 $downurl='http://www.abc.com/abc/'.$urlname.'.mp3';

$url       = $_SERVER["HTTP_REFERER"];   //获取完整的来路URL
$str   = str_replace("http://","",$url);  //去掉http://
$strdomain = explode("/",$str);               // 以“/”分开成数组
$domain    = $strdomain[0];              //取第一个“/”以前的字符
if ($domain=="www.123.com"){

 header("location:$downurl");

}
if ($domain==""){
 header("location:http://www.123.com/daolian.mp3");
}
if ($domain!="www.123.com"){

 header("location:http://www.123.com/daolian.mp3");

}
 ?>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
修改完成后,防盗链防下载是实现了,在网页中的播放器播放http://www.123.com/x.php/love.mp3,却播放不了,请问这是代码究竟是什么地方出了问题啊。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template