Jos*_*ers 4 php mp3 hide audio-player
我有一个使用以下语法链接到歌曲的音乐播放器:
<li><a href="" data-src="http://s3.amazonaws.com/audiojs/02-juicy-r.mp3">title</a></li>
Run Code Online (Sandbox Code Playgroud)
有没有办法让我可以执行服务器端,然后为用户显示(如下所示)?
在搜索时,我碰到了这个...我喜欢有一个外部文件背后有这个数据的想法...像:
<?php
// get-file.php
// call with: http://yoururl.com/path/get-file.php?id=1
$id = (isset($_GET["id"])) ? strval($_GET["id"]) : "1";
// lookup
$url[1] = 'link.mp3';
$url[2] = 'link2.mp3';
header("Location: $url[$id]");
exit;
?>
Run Code Online (Sandbox Code Playgroud)
然后使用:http://yoururl.com/path/get-file.php?id = 1作为链接...唯一的问题是当你输入http://yoururl.com/path/get-file时. php?id = 1用户直接进入文件...是否有任何方法可以禁用该功能......也许是get-file.php本身的一些代码?
好吧,所以我做了一些我很满意的事情......虽然不是很安全,但它确实帮我模糊了一点.
首先,我使用AudioJS播放器播放音乐 - 可以找到:http://kolber.github.com/audiojs/
基本上我做的是:
所以,现在我的内联javascript看起来像:
<script type="text/javascript">
$(function() {
// Play entire album
var a = audiojs.createAll({
trackEnded: function() {
var next = $("ul li.playing").next();
if (!next.length) next = $("ul li").first();
next.addClass("playing").siblings().removeClass("playing");
audio.load($("a", next).attr("key") + "mp3");
audio.play();
}
});
// Load the first song
var audio = a[0];
first = $("ul a").attr("key") + "mp3";
$("ul li").first().addClass("playing");
audio.load(first);
// Load when clicked
$("ul li").click(function(e) {
e.preventDefault();
$(this).addClass("playing").siblings().removeClass("playing");
audio.load($('a', this).attr('key') + "mp3");
audio.play();
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我的链接看起来像:
<a href="<?php $link = 'http://itunes.apple.com/us/album/falling/id504779876?i=504779883&uo=4'; $obfuscatedLink = ""; for ($i=0; $i<strlen($link); $i++){ $obfuscatedLink .= "&#" . ord($link[$i]) . ";"; } echo $obfuscatedLink; ?>" target="itunes_store" key="<?php $link = './8249795872/9273847591.'; $obfuscatedLink = ""; for ($i=0; $i<strlen($link); $i++){ $obfuscatedLink .= "&#" . ord($link[$i]) . ";"; } echo $obfuscatedLink; ?>">Falling</a>
Run Code Online (Sandbox Code Playgroud)
当您在浏览器中加载它并查看源代码时,您将看到:
<a href="http://itunes.apple.com/us/album/falling/id504779876?i=504779883&uo=4" target="itunes_store" key="./8249795872/9273847591.">Falling</a>
Run Code Online (Sandbox Code Playgroud)
然后,当您使用Web Inspector或Firebug时,您将看到:
<a href="http://itunes.apple.com/us/album/falling/id504779876?i=504779883&uo=4" target="itunes_store" key="./8249795872/9273847591.">Falling</a> - *which doesn't completely give the url away
Run Code Online (Sandbox Code Playgroud)
基本上我所做的就是让链接看起来像是某种类型的api-key.很酷的是,您不能直接从视图源复制链接,也不能直接从Web Inspector/Firebug复制链接.它不是万无一失的,绝对可以被打破,但用户必须知道他们在做什么.它让大多数人远离,但仍然允许玩家获得播放歌曲所需的网址:)
*另外,我从Stack Exchange上的某个地方获得了php obfusticate脚本,但不知道在哪里.