Jump to content

Referrer checking, hiding actual file locations


DaveLinger

Recommended Posts

So basically on this website I'm building, I have a bunch of mp3 files that I want people to be able to listen to using a flash mp3 player on the site, and I want them to be able to (I suppose) save the files to their hard drives, but NOT be able to link directly to the mp3 from other websites.

 

So here's my code:

 

<?php
$gid = $_GET['g']; //game ID number. Each game has its own music directory.
$file = $_GET['f']; //filename minus the .mp3
$yoursite = "www.xxx.com";
$yoursite2 = "xxx.com";

$referer = $_SERVER['HTTP_REFERER'];

if ($referer == "") {
$domain = $yoursite; 
} else { 
$domain = parse_url($referer);
} 

if($domain['host'] == $yoursite || $domain['host'] == $yoursite2) { 

$location = "/games/".$gid."/music/".$file.".mp3";

header("Location: $location");

} else { 

header("Location: http://www.xxx.com"); 

} 

?>

 

But the problem with this is that, assuming they ARE on the site, it just gives them the direct URL to the file. How can I set it so that rather than essentially redirecting to the mp3 file, the php file actually outputs the contents of the mp3 file? For example they could save the php file to their hard drive and rename it to mp3 and it would play. I think I've seen this done before.

Link to comment
Share on other sites

But why even use that?

Use .htaccess to redirect .mp3 extensions to a php script

 

or if yer server is PATH_INFO enabled, ya can do the same without .htaccess

 

put the mp3's into an off-web folder, so they cant directly link to the mp3.

 

and use a session cookie to track that its a valid logged in user.

 

have yer script check the session, send the proper header, and readfile :)

boom yer done.

 

can prolly make a small mp3 with a message 'Mp3's brought to you by xxx.... Please no hotlinking'

 

:)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.