Zend - The PHP Company




Miscellaneous

Add Code


Random background music script  

Type: application
Added by: bighead2002
Entered: 14/12/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 8002

Use this script to automatically add a random background music to your site. Requires the use of an extra frame, to make sure the music continues, even if a visitor navigates to another part of your site.

This script ain't perfect yet! I've never learned PHP, but I managed to wrote this one so any suggestion is greatly appreciated!

Some words in the script are in Dutch. If this gives any trouble, just mail me at mark@mjansen.doge.nl and I'll translate them for you.



<?php
// Beginning php

// Saving the page header in the variable $head.
$head = <<<ENDH
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>Achtergrondmuziek</title>
  </head>

  <body topmargin="0" leftmargin="0" text="#ffffff" link="#FE683A" vlink="#000000" alink="#000080" bgcolor="#FFFFFF" background="/images/linker-menu-achtergrond.gif">
  
ENDH;
// End of page header

// Saving the page footer in the variable $tail.
$tail = <<<ENDT
      </body>
</html>
ENDT;
// End of page footer

// Set up variables that will be saved in the cookies
// Define unique cookie prefix
$ID "Jubal-achtergrondmuziek"
// Cookie lifetime in seconds (in this example, three days)
$cookie_life 365*24*3600
// Name of cookie that holds the user's preference
$n_pref $ID "_Preference"


// this part creates a random background music with title

// makes sure the random number really is random
mt_srand ((double) microtime() * 1000000);
// creates a random number
$number mt_rand  (125);

if (
$number == (1)) {
$midifile=("/multimedia/midifiles/change_the_world.mid");
$midititle="Change the world";
$timervalue=256000;
}
if (
$number == (2)){
$midifile=("/multimedia/midifiles/iwillal.mid");
$midititle="I will always love you";
$timervalue=256000;
}
if (
$number == (3)){
$midifile=("/multimedia/midifiles/layla.mid");
$midititle="Layla";
$timervalue=322000;
}
if (
$number == (4)){
$midifile=("/multimedia/midifiles/tearsihe.mid");
$midititle="Tears in heaven";
$timervalue=284000;
}
if (
$number == (5)){
$midifile=("/multimedia/midifiles/when-you-believe.mid");
$midititle="When you believe";
$timervalue=273000;
}
if (
$number == (6)){
$midifile=("/multimedia/midifiles/white_ro.mid");
$midititle="White Rose";
$timervalue=356000;
}
if (
$number == (7)){
$midifile=("/multimedia/midifiles/wonderfu.mid");
$midititle="Wonderful World";
$timervalue=247000;
}
if (
$number == (8)){
$midifile=("/multimedia/midifiles/1492.mid");
$midititle="1492";
$timervalue=312000;
}
if (
$number == (9)){
$midifile=("/multimedia/midifiles/bestfrnd.mid");
$midititle="You're my best friend";
$timervalue=191000;
}
if (
$number == (10)){
$midifile=("/multimedia/midifiles/bohemian.mid");
$midititle="Bohemian Rhapsody";
$timervalue=350000;
}
if (
$number == (11)){
$midifile=("/multimedia/midifiles/the_empire_strikes_back.mid");
$midititle="The empire strikes back";
$timervalue=225000;
}
if (
$number == (12)){
$midifile=("/multimedia/midifiles/indysong.mid");
$midititle="Indiana Jones";
$timervalue=330000;
}
if (
$number == (13)){
$midifile=("/multimedia/midifiles/5thbeethoven.mid");
$midititle="5de Beethoven";
$timervalue=555000;
}
if (
$number == (14)){
$midifile=("/multimedia/midifiles/cats_memory.mid");
$midititle="Cats Memory";
$timervalue=240000;
}
if (
$number == (15)){
$midifile=("/multimedia/midifiles/d_queen.mid");
$midititle="Dancing Queen";
$timervalue=250000;
}
if (
$number == (16)){
$midifile=("/multimedia/midifiles/don't_cry_for_me_argentina.mid");
$midititle="Don't cry for me Argentina";
$timervalue=362000;
}
if (
$number == (17)){
$midifile=("/multimedia/midifiles/fernando.mid");
$midititle="Fernando";
$timervalue=275000;
}
if (
$number == (18)){
$midifile=("/multimedia/midifiles/mammamia.mid");
$midititle="Mammamia";
$timervalue=233000;
}
if (
$number == (19)){
$midifile=("/multimedia/midifiles/msaigong.mid");
$midititle="Miss Saigon";
$timervalue=552000;
}
if (
$number == (20)){
$midifile=("/multimedia/midifiles/phantom.mid");
$midititle="the Phantom of the Opera";
$timervalue=270000;
}
if (
$number == (21)){
$midifile=("/multimedia/midifiles/summerlovegrease.mid");
$midititle="Summerlove Grease";
$timervalue=220000;
}
if (
$number == (22)){
$midifile=("/multimedia/midifiles/waterloo.mid");
$midititle="Waterloo";
$timervalue=190000;
}
if (
$number == (23)){
$midifile=("/multimedia/midifiles/whatsup.mid");
$midititle="What's up";
$timervalue=325000;
}
if (
$number == (24)){
$midifile=("/multimedia/midifiles/bitdust2.mid");
$midititle="Another one bites the Dust";
$timervalue=192000;
}
if (
$number == (25)){
$midifile=("/multimedia/midifiles/i_would_do_anything_for_love.mid");
$midititle="I would do anything for love";
$timervalue=145000;
}




// when a form is used to come to this page
if( isset($preference)) { 
   if (
$preference == "on") {
       $
$n_pref "on";
       
Setcookie($n_pref,"on",time()+$cookie_life);
   }
   else {
       $
$n_pref "off";
       
Setcookie($n_pref,"off",time()+$cookie_life);
       }
}


// users who not have been here before
// the cookie will have no value
if(!$$n_pref) {  
    
$text ="you are new";
    
Setcookie($n_pref,"on",time()+$cookie_life);
    $
$n_pref="on";
}
// and the one's coming back
//
// else {
//    $text = $$n_pref;
// }

echo $head;
echo 
"<table border=0 cellpadding=0 cellspacing=0 width=115><tr><td width=100><img border=0 src=images/logo-online.gif valign=top align=top></td></tr><tr><td><center>";


if ($
$n_pref =="on") {

echo 
"<EMBED SRC=";
echo 
$midifile;
echo 
" WIDTH=0 HEIGHT=0 AUTOSTART=TRUE>";
echo 
"<small><small>Achtergrondmuziek: </small><b>";
echo 
$midititle;
echo 
"</b>";

// setTimeout("parent.midiframe.location.href='midi.html'",    timer) ;

echo "<script>setTimeout('parent.midiframe.location.href=";
echo 
$PHP_SELF;
echo 
"?preference=on',";
echo 
$timervalue;
echo 
" );";
echo 
"</script>";

?>

<form action="<?php echo $PHP_SELF ?>" method="POST"> 
<input name="preference" type="hidden" value="off">
<input type=submit value="Muziek uit"></form>
<?php 

}    

else 
{
?>

<form action="<?php echo $PHP_SELF ?>" method="POST"> 
<input name="preference" type="hidden" value="on">
<input type=submit value="Muziek aan"></form>
<?php 
echo "<small><small>(Momenteel heeft u geen achtergrondmuziek aan staan)<br></small></small>";
}

echo 
"</center></td><td width=15></td></tr></table>";
echo 
$tail;

?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories