A Small PHP Script for Shoutcast Users

December 15 20072 comments | post comment

I recently setup a shoutcast server and wanted to hide the port I was using. I don’t like nasty looking URLs like the following: http://radiostation.com:8002/listen.pls. I wanted to be able to type out the address much easier than that, something like http://radiostation.com/listen.pls.

What I ended up doing was create a simple PHP script and a mod_rewrite rule to create the link.

Here is the PHP script:
listen.php

<?php
header
("Content-type:audio/x-scpls");
echo
"[playlist]
NumberOfEntries=1
File1=http://lunchboxradio.com:8000/"
;
?>

It is sending the document as a media type instead of an html doc, which causes your browser to attempt to download it instead of displaying the files contents. Generally you will be prompted to open the file in your default media player, which will usually be fine to listen to the stream.

Instead of pointing users to a PHP file, I wanted to direct them to a PLS. You just need to add a rule to an htaccess file that redirects all requests to FILENAME.PLS to FILENAME.PHP and voila, you are done.

My .htaccess file:
.htaccess

RewriteEngine On
RewriteRule
^LunchBoxRadio.pls$ listen.php [L]

Now I just have to link to http://lunchboxradio.com/LunchBoxRadio.pls to listen to the stream. This is way better than the long ugly URL that is the default. 

Comments

1    Matt   December 19 2007

You could use port forwarding at the router level as well if you’re so inclined. But I like the rewriteusage.

2    ecsyle   December 26 2007

This is on a dedicated virtual server though. I don’t think I could do something like that. If I ran this from home it would probably be better to not have PHP and Apache do extra work when it isn’t necessary.

You need to register or log in to leave a comment.