Need music to default "on" using CMS


I am using a php/mysql based CMS that has a music feature. Problem is in order to hear the music, you have to click the “music on” link. I want it to default to music on when you hit the site, instead of being off. I have tried just about everything I can, but nothing is working. The best I can do is music on all of the time with no option of being able to turn it off. I am going to copy the code below. Any help is appreciated!

<? foreach ($_GET as $varible => $value) { $$varible = $value; } foreach ($_POST as $varible => $value) { $$varible = $value; } include_once("include/"); session_register("s_25music"); if ($musicplayer=="on"){ $HTTP_SESSION_VARS["s_25music"]=1; }else if ($musicplayer=="off"){ $HTTP_SESSION_VARS["s_25music"]=2; }else { if ($HTTP_SESSION_VARS["s_25music"]!=2); //$HTTP_SESSION_VARS["s_25music"]=1; } if ($config->midi){ if ($HTTP_SESSION_VARS["s_25music"]==1){ //$player="Music Off"; $player="Music On"; $music="n n n n n"; $pg=$music.$pg; } else { $player="Music Off"; //$player="Music On"; } echo $pg; } ?>

Both and are non-existing/deprecated elements in HTML. This isn’t a PHP issue. Use objects instead.


Thanks for the reply. Can you explain or show me an example of how to use this as an object?
I am a newbie and of course did not write this code, so it is all trial and error for me at this point.


Although they may be deprecated, you can check out … EMBED.html

As may be pointed out on some of those pages, you should use sound sparingly… Many can find it annoying.

Also as Zyppora points out, this not really a PHP issue rather an HTML issue. I suspect the objects he might be referring to might be using Plugin objects (Quicktime, Flash, etc…)

Okay. I think I understand. Now, If I have it load as an object, my problem becomes that I have over 100 templates within this CMS. Will I have to add the code for the player in each template or can I call it using php and just add it to the main index.php file?

I hope this makes sense.


That depends on how you are loading the music.

I would think you could just load the player (object) and then dynamically decide (with php) which music you wanted it to play.

Two things. First, when you say “then dynamically decide (with php)” looking at the above code, how would you call the music file that is loaded in the midi folder?

Second, looking at the code above. The biggest issue here is that the music plays just fine as it is, but you just have to click the “Music On” link. Is there anything that you see that could be changed from loading with the default being “off” to the default being “on”? If I swap out the 1 and the 2 (on & off) within the code, the music will play as soon as you hit the page. Problem is that you can not shut it off.

Thanks again for your help.

That depends on what method you use play the music. If you use a “Plugin” you would need to know the syntax for that particular plugin. You would then insert the name of your music file dynamically using the PHP code.

As an eample I have a “Video” player on my one site that uses an applet to show the video.


<APPLET CODE=LoadJpg.class ARCHIVE=loadjpg.jar name=NCApplet
<param name=ImageTransferPort value=8081>
<param name=HashingKey value=0>
<? if ($_get['2'] == 'admin' ){
        echo '<param name=ID value=admin>';
        echo '<param name=PASSWORD value=XXXXXXX>';
} else {
        echo '<param name=ID value=guest>';
        echo '<param name=PASSWORD value=guest>';

<param name="VER_FLIP" value="0">
<param name="HOR_FLIP" value="0">
<param name="Timestamp" value="true">
<param name="Expansion" value="2">


You just need to “inter-mingle” your PHP with your HTML to ultimately render an HTML page (with the Plugin/applet/object). PHP can be used to create your logic.

Again, a “Player” rendered on the page would generally allow all of this. You just need to find one that you can use. Then you need to evaluate it’s programing requirements (i.e. what code allows the options you want) then put it in to your page. I don’t generally do audio in my pages, so I don’t know how to advise you which one to use.

So, when I add this to my html page, it works just fine for my needs.

I would then take this and try to incorporate it into the bit of code that I copied above and then it would play on my pages, correct?

Thanks again.

Here is how I ended up calling the midi file and incorporating it into my php:


The only problem now is when you turn the player off and you go to another page in the site, it starts playing again!

Well yes, that’s the downside of what you’re trying to do (although some would say the downside is that the music restarts upon page refresh, rather than keep going). autostart=“true” will ALWAYS uphold, unless you have PHP tell it otherwise. And PHP won’t detect whether or not the user stopped the music halfway through the previous page (unless you want to get yourself tangled up in AJAX).

I’m still wondering why you’re using though. The link I gave you gives a perfect example of playing sound through an , which is (supposed to be) browser independent (and thus compatible with every browser your visitors might use).

As peg110 pointed out though, you’ll want to reconsider whether or not your visitors actually want sounds on your webpage. Me for instance, I play music through my favorite music player. If a visit a webpage that starts blasting music, I click it away immediately, and I don’t come back.

Sponsor our Newsletter | Privacy Policy | Terms of Service