Mark B
<FilesMatch "\.(mp3|ogg|m4a)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "http://yourdomain.tld" </IfModule> </FilesMatch>
--
You received this message because you are subscribed to the Google Groups "jPlayer: the CSS styleable jQuery audio player plugin" group.
To post to this group, send email to jpl...@googlegroups.com.
To unsubscribe from this group, send email to jplayer+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jplayer?hl=en.
What's to stop someone calling the PHP file directly and then grabbing
the file that way?
I've been wondering whether you could restrict the calling of certain
server-side code to the same domain or IP, these details could maybe
spoofed but it would stop 99% of people downloading the file.
Mark B
Thanks for the tips..
generally, you're right @Mark B.
I guess, YWFTDG has/wants to deal with the same task, I just had to: Not
to offer (maybe copyright sensitive) mp3/Ogg -Files over an alltime
valid URL, which is vulnerable against deep-linking...
My kind of solution was to install an extra webserver (keywords to
google for: lighttpd with mod.sec_download).
With this, the files are served just for a given time, e.g. 300sec.,
coming from a folder, which is located outside the webroot.
This way, the URLs to the files get invalid after that given time,
making deep-linking senseless...A side-effect: this server is really fast...
But, yes, only possible, if you have the chance to install extra stuff
@YWFTDG
Btw.: @happyworm, @ Mark P in particular:
Many many thanks for this cool piece of work, the jplayer, and for your
endless patience in answering support questions! How do you still find
time for your everyday work? :)
Best Regards,
Holger
<?
$sku = $_GET['sku'];
$filename = $_GET['file'];
$file = '/var/www/vhosts/mydomain.com/audio/'.$sku.'/'.$filename.'';
$mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";
if(file_exists($file)){
header('Content-type: $mime_type');
header('Content-length: ' . filesize($file));
header('Content-Disposition: filename=" ' . $filename . ' " ');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($file);
}else{
header("HTTP/1.0 404 Not Found");
}
?>
The player works fine when calling the mp3 files directly but when I
changed over to .php file to send the files, this caused it to break
down.
Anyone got any thoughts, ideas? I am pretty much stuck now, spent
about 10 hours debugging yesterday, nothing..
I finally had time to test the solution I had imagined and it works
like a charm!
Whenever a track is played by the jplayer, I send an ajax request to a
php file, that creates two session vars: one with the id of the played
track, another with the timestamp I started playing it.
Now, the php page that serves the MP3 files first checks if these two
session vars exist, and that the track started playing less than, say,
three seconds ago. Only if this is the case, it redirects to the mp3
using the headers system.
So, it's not an absolutely surefire solution (nothing is, as you
said), but I'm sure it will be enough for a vast majority of the
visitors :)
Regards,
Remy
Let me know if you can, but I like your idea on the session solution
too, I will have to figure out what you are doing there.
thanks,
-Michael
On Mar 18, 6:18 am, Remy <remydoo...@gmail.com> wrote:
> I don't really see how the access to the php file could be limited,
> since the jplayer doesn't send a HTTP_REFERER to the PHP file. That
> was my main problem in this thread:http://www.google.com/url?sa=D&q=http://groups.google.com/group/jplay...
On Mar 16, 2:19 pm, YWFTDG <thedesigngrap...@gmail.com> wrote:
Here is the code and headers I use in the page that serves the MP3, if
that's any help :
session_start();
$idmp3 = $_GET["id"];
if ( (isset($_SESSION["title_played"])) &&
(isset($_SESSION["time_played"])) &&
($idmp3 == $_SESSION["title_played"]) && (time()-
$_SESSION["time_played"] < 3) )
{
$path = "mypath/".$idmp3.".mp3";
header('Content-type: audio/mpeg');
header('Content-Length: '.filesize($path)); // provide file size
header("Expires: -1");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
readfile($path);
}
Hope it helps!
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){
var playItem = 0;
<?
$path = '/mydomain/full/path/audio/'.$sku.'/'; -- hidden for
security
$allowed_types = array('mp3');
if(file_exists($path)) { ?>
var myPlayList = [
<?
$audioFiles = opendir($path);
$count = 0;
while($file = readdir($audioFiles)){
if(in_array(strtolower(substr($file ,-3)),$allowed_types)) {
$count++;
?>
{name:"<?=substr($file, 0, -4)?>",mp3:"<?=$baseURL?
>playerfile.php?sku=<?=$sku?>&file=<?=$file?>"},
<?
}
}
?>
];
<? } // end if exists ?>
// Local copy of jQuery selectors, for performance.
var jpPlayTime = $j("#jplayer_play_time");
var jpTotalTime = $j("#jplayer_total_time");
var jpStatus = $j("#demo_status"); // For displaying information
about jPlayer's status in the demo page
$j("#jquery_jplayer").jPlayer({
ready: function() {
displayPlayList();
playListInit(false); // Parameter is a boolean for autoplay.
demoInstanceInfo(this.element, $j("#demo_info")); // This
displays information about jPlayer's configuration in the demo page
},
swfPath: "/Scripts/jplayer",
oggSupport: false
})
.jPlayer("onProgressChange", function(loadPercent,
playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
jpPlayTime.text($j.jPlayer.convertTime(playedTime));
jpTotalTime.text($j.jPlayer.convertTime(totalTime));
demoStatusInfo(this.element, jpStatus); // This displays
information about jPlayer's status in the demo page
})
.jPlayer("onSoundComplete", function() {
playListNext();
});
$j("#jplayer_previous").click( function() {
playListPrev();
return false;
});
$j("#jplayer_next").click( function() {
playListNext();
return false;
});
function displayPlayList() {
for (i=0; i < myPlayList.length; i++) {
$j("#jplayer_playlist ul").append("<li
id='jplayer_playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
$j("#jplayer_playlist_item_"+i).data( "index",
i ).click( function() {
var index = $j(this).data("index");
if (playItem != index) {
playListChange( index );
} else {
$j("#jquery_jplayer").jPlayer("play");
}
});
}
}
function playListInit(autoplay) {
if(autoplay) {
playListChange( playItem );
} else {
playListConfig( playItem );
}
}
function playListConfig( index ) {
$j("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current");
$j("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
playItem = index;
$j("#jquery_jplayer").jPlayer("setFile",
myPlayList[playItem].mp3);
}
function playListChange( index ) {
playListConfig( index );
$j("#jquery_jplayer").jPlayer("play");
}
function playListNext() {
var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
playListChange( index );
}
function playListPrev() {
var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
playListChange( index );
}
});
</script>
<div id="jquery_jplayer"></div>
<div class="jp-playlist-player">
<div class="jp-interface">
<ul class="jp-controls">
<li id="jplayer_play" class="jp-play">play</li>
<li id="jplayer_pause" class="jp-pause">pause</li>
<li id="jplayer_stop" class="jp-stop">stop</li>
<li id="jplayer_volume_min" class="jp-volume-min">min volume</
li>
<li id="jplayer_volume_max" class="jp-volume-max">max volume</
li>
<li id="jplayer_previous" class="jp-previous">previous</li>
<li id="jplayer_next" class="jp-next">next</li>
</ul>
<div class="jp-progress">
<div id="jplayer_load_bar" class="jp-load-bar">
<div id="jplayer_play_bar" class="jp-play-bar"></div>
</div>
</div>
<div id="jplayer_volume_bar" class="jp-volume-bar">
<div id="jplayer_volume_bar_value" class="jp-volume-bar-value"></
div>
</div>
<div id="jplayer_play_time" class="jp-play-time"></div>
<div id="jplayer_total_time" class="jp-total-time"></div>
</div>
<div id="demo_status"></div>
<div id="jplayer_playlist" class="jp-playlist">
<ul>
<!-- The function displayPlayList() uses this unordered list -->
</ul>
</div>
</div>
> $j("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_curren t");
<?
$sku = $_GET['sku'];
$filename = $_GET['file'];
$file = '/var/www/vhosts/mydomain.com/audio/'.$sku.'/'.$filename.'';
$mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";
if(file_exists($file)){
header('Content-type: $mime_type');
header('Content-length: ' . filesize($file));
header('Content-Disposition: filename=" ' . $filename . ' " ');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($file);
}else{
header("HTTP/1.0 404 Not Found");
}
?>