Alright im making a php script that is included at the bottom of each page of a site, and at the bottom it will show a link saying "No Media Selected" and if you click it, it will refresh the page and instead have a link to a certain MIDI track that will start playing (eg. FFX - Other World). You can then click it again to turn off the music.

The trick of it is, the music that is played is determined on the page that your viewing, so in my case its a Final Fantasy gaming site, so if you were looking at the page about Chocobos, Chocobo music will play, if you are looking at a page for Items, shop music will play.

to get this to work I need to develop a method that the page viewed is somehow translated into a variable and then I can make if statements

(eg. http://www.ffextreme.com/chocobo.php

I need it so the script takes the "chocobo" and applies it to the script, so then I can have

if (blah blah == chocobo) {
display this link and play this
}

anyone know how I can do this? or has any better ideas than mine on how I could go about doing this?

    this is basically the same as I have at http://www.propertyinvestor.info where I call menu.php and it sets up the buttons and hides the button for the active page.

    <?php
    $menuPage = "news";
    include("menu.php");
    ?>

    Believe it or not, your requirement is little different.

    I don't know the code you need to output but I'm assuming you have midi files sitting in a folder and you need to point your html to them. Depending on the complexity of your site you can have simple if statements or even switch. If more complex then you could use a database.

    Simpler again is to pass the name of the file you want. Chocobo page knows it wants a particular file name.

    have I helped?

      you can start and stop from a link, without going to have refresh the page, it can be done in javascript and this script is avalible at javascript.com or it was javascriptsource.com somehting like that.

        to sarah: so all I need to do is put that code on each site (changing the variable value) and when it includes it will send that variable value to the menu.php (in my case music.php) and then I can have the if statements that guide it to an html file which plays the MIDI? 😃

        and to abnfire... which site is it? lol

          The page knows its own name already: $PHP_SELF ($_SERVER['PHP_SELF'] to give its full name). Other things in that array may be useful, also.

          Have your MIDI-playing pages look at that when deciding which bit of music to play. One intelligent approach to this job would be to put the "play a MIDI file on this page" code into a separate file and insert it whenever appropriate using include().

          In the separate file, have an array

          $soundtracks = array(
             'shop.php' => 'shop_muzak.mid',
             'chocobo.php' => 'chocobo.mid',
          //...etc.
          );
          

          The code that selects the soundtrack is then

          if(isset($soundtracks[$_SERVER['PHP_SELF']]))
          {  // We have a soundtrack for this page. Use it
             $soundtrack = $soundtracks[$_SERVER['PHP_SELF']];
             //insert html stuff here.
          }
          else
          {  // Funny, there is no soundtrack for this page
             // Do something else instead.
             // (A default soundtrack? Silence?
             // Nothing at all?)
          }
          

            ok weedpacket that helps a lot... would there be a way to display "No Soundtrack Available" if there isnt a music file matching the page.php? so it checks and decides if there is one or not first.

              just use if statment to check the file:

              if(!file_exists("location-with-file-name")){
              echo "link for midi is not avalible";
              }

                Originally posted by Mistah Roth
                ok weedpacket that helps a lot... would there be a way to display "No Soundtrack Available" if there isnt a music file matching the page.php? so it checks and decides if there is one or not first.

                Yep; that's built into my code. If the page is found in the list, you'd have the code embed the HTML for linking to the MIDI. If the page isn't found, PHP will do whatever is specifed in the else{Do something else instead} block; that's where you'd put the HTML for your "No Soundtrack Available" notice.

                  ok so I made a file called music.php and stuck this code into it:

                  <?php
                  $soundtracks = array(
                     'shop.php' => 'shop.mid',
                     'chocobo.php' => 'chocobo.mid',
                     'intro.php' => 'welcome.mid',
                  );
                  
                  if(isset($soundtracks[$_SERVER['PHP_SELF']])){ 
                     $soundtrack = $soundtracks[$_SERVER['PHP_SELF']];
                  }
                  else{ 
                  	echo "No Soundtrack Available";
                  }
                  ?>

                  and then I have a MIDI called welcome.mid and I made a file called intro.php with this code at the bottom:

                  <?php include("music.php");?>

                  and it should work but it just says No Soundtrack Available 😕

                    Originally posted by Weedpacket

                    Yep; that's built into my code. If the page is found in the list, you'd have the code embed the HTML for linking to the MIDI. If the page isn't found, PHP will do whatever is specifed in the else{Do something else instead} block; that's where you'd put the HTML for your "No Soundtrack Available" notice.

                    Ahh, logic!

                      Try this:

                      echo "$_SERVER[PHP_SELF]";

                      Quite likely, your array should be:

                      $soundtracks = array(
                         '/shop.php' => 'shop.mid',
                         '/chocobo.php' => 'chocobo.mid',
                         '/intro.php' => 'welcome.mid',

                      'cause PHP_SELF generally has a leading slash.....

                        Is that because $_SERVER[PHP_SELF] returns music.php? Maybe it shouldn't be included, or the

                        $soundtrack = $soundtracks[$_SERVER['PHP_SELF']];
                        

                        shouldn't be included, rather put in each page that music.php is being included into.

                        Matt

                          Ok I figured out why it was saying "No Soundtrack Available", it was because it was located in the items folder of the main site, so I had to put /items/shop.php or whatever in the array, now that doesnt show up but no music actually plays.....

                          is it just me or is there no actual code that PLAYS the music... it just assigns it to the soundtrack variable and leaves it... (what is the PHP code for the playing part?)

                            Um, not aware of "MIDI functions" in the PHP manual....

                            Aren't we just talking HTML here, maybe <embed> or some such?

                            So, you'd have PHP echo "<embed>........." or whatever....

                              <embed src="XXX.XXX" console="smallconsole" loop="XXX | false(default)" volume="XX" autostart="false" height="60" width="145">

                                ...so I had to put /items/shop.php or whatever in the array,...

                                Just checked the manual, yeah: absolute name. Or use basename($POST[$SERVER['PHP_SELF']]).

                                is it just me or is there no actual code that PLAYS the music... it just assigns it to the soundtrack variable and leaves it...

                                Well I didn't write any; didn't know what the HTML was to embed a MIDI file. Thought you did 🙂

                                  alright thanks... I got it all working perfectly thanks for your help everyone 🙂

                                    actually one more thing.... im trying to make the link thing so it takes whats ALREADY THERE + &music=yes

                                    so if I click it from

                                    index.php?nav=menu&main=news

                                    it will goto

                                    index.php?nav=menu&main=news&music=yes

                                    what do I link to, to make that happen? 🙂

                                      Write a Reply...