tags:

views:

86

answers:

4

Hello everyone and thank you for your time. I would just like to say that even though I'm no noobie at php, I don't know everything yet and I still lack some knowledge to be able to tackle some of these problems.

My current dilemma is:

I have a database with user-made songs that have all kinds of information including the location of said songs. The way I have it working is I have a php script that echos a xspf playlist document for a flash player to read for whoever is browsing the songs. (the best part being that the player doesn't care that it's a php file as long as it receives the correct xml format).

The problem is that anybody can look at the source (for example find that the player uses xspf.php?=song_id=10), and the php file will output everything in plain text. How could I hide or encrypt the location of the mp3 from users but still be able for the player to work properly?

I will also in the future have users be able to download tracks but I want to find a way to hide the location or maybe if it isn't too hard generate a temporary url? Do share what you think is best to tackle this problem.

And again thanks in advance for any responses!

+5  A: 

Maybe the player also doesn't care about the extension of the files. You can put mp3 entries into your playlist with url's like play.php?songid=some_encoded_value.

Then in play.php, you have to verify the user to have a valid session. You can also keep record of the number of times a songid (if generated) can be used to access a song - set this 1 or 2? But depending on the player behavior (multiple requests on broken connection, etc) this may not be the safest idea, but should be ok generally.

Note however that advanced users / developers who want to download the songs will be able nevertheless with more or less hacking. A solution for that would be streaming the songs encoded into the player, where the player would decode.

But then the decoder algorithm in the flash player could be deciphered, etc.

The more you work the safer you are, but absolute safety is not really possible.

Edit: The songid scheme would naturally require some mapping table between actual songid's and real mp3 files. The mapping can be in session memory, but preferrably in a database. The play.php file would use the readfile function (or similar) to output the song on the output. Alternatively, mp3 files can also be stored in the database in binary blobs.

ron
I don't really care if they download the songs since they will be able to, it's just the file structure I don't want exposed.
Tek
I would also like to thank you for a partial answer it helped to know that the player also didn't care about the extension of the files. All I did was add an extra variable that made the song downloadable through readfile() without exposing any internal directories. Thank you ron!
Tek
+2  A: 

I don't know PHP, but concept wise, I would suggest the following:

  1. Use some encryption key that is specific for the current user's session and pass that along to the xspf.php file.
  2. Do not store the direct location of the MP3 files in the generated XML, but use a PHP file (with the user generated, session related key passed in - which is then validated) to serve the MP3 file to the Flash plugin, and keep the MP3 files in a directory not accessible through a static and public URL (so ideally outside of your web root).
Wim Hollebrandse
Thank you Wim for your suggestion, I wish I could select multiple answers!
Tek
+1  A: 

I have restricted access to files by linking to a php script which checks if the user has access to the file, and echoing the file with readfile() if the user has access to the file. You can then keep the file in a directory that can't be accessed directly through a URL.

Kristian J.
Thanks, readfile() did the trick. This was the closest answer to my question although if it wasn't for everyone I wouldn't have been able to put the pieces together.
Tek
+1  A: 

Don't bother. Consider the situation where the Flash Player is behind a proxy. You'll see every URL in the proxy anyway. To see for yourself, use Fiddler (free tool, acts as proxy and shows HTTP traffic).

MSalters
But at least it doesn't have to be a direct download link which can potentially be shared with the whole world.
Wim Hollebrandse
What do you mean? The URL shown in Fiddler can be shared with the world.
MSalters
Well yes, but if the URL contains a session related identifier with user identity verification plus timestamp, and performs a validation check before serving up the file, this will only work for the appropriately logged in user. Anyone else would get a login screen or some error page - depending on how the check is implemented in the PHP page.
Wim Hollebrandse