Forum Moderators: coopster

Message Too Old, No Replies

Passing a variable from an intro page using php

         

Dstraction

1:39 pm on May 6, 2006 (gmt 0)

10+ Year Member



Hi all!

I was going to use javascript to do this but I was told on the javascript forum that it would be far easier using a server-side language like php.

Is it possible to pass a global variable from an intro page?

Currently, I have a flash intro and the option to 'Skip Intro' on the intro page.

I'd also like an option on the intro page to 'Skip intro and turn the music off' on all pages on the site.
That way my dial-up users can enjoy the site without the wait.

My current code works fine in IE 6 and my next project is to get it to work in FireFox (input on this would be great too!)
Currently my music code for each page is very simply:

<script language="JavaScript">

var NFsong = "http://example.com/mm5/music/m3u/storefront.m3u" [the *.m3u references an mp3 file and is different on each page of the site]

</script>

And the global footer has the player code:

<script language="javascript">
<!--
document.write("PAUSE&nbsp;&nbsp;<embed src=\""+NFsong+"\" style=\"width:44px;height:26px\" loop=\"true\" >&nbsp;MUSIC");
//-->
</script>
<BR>

Any help on passing a global variable from the intro page would be GREATLY appreciated!

Thanks in advance!

Joe

[edited by: coopster at 4:16 pm (utc) on May 8, 2006]
[edit reason] removed urls per TOS [webmasterworld.com] [/edit]

eelixduppy

9:38 pm on May 6, 2006 (gmt 0)



Hello..

you could do something like this:

footer.php

if($_GET[music] == 1)
{
echo "<script language='javascript'>
document.write(\"PAUSE&nbsp;&nbsp;<embed src=\"'+NFsong+'\" style='width:44px;height:26px' loop='true' >&nbsp;MUSIC\");
</script> ";
echo "<a href='$_SERVER[PHP_SELF]?music=0'>Stop music</a>";

else {
echo "<a href='$_SERVER[PHP_SELF]?music=1'>Play music</a>";
}

Now whenever you want to include this music you just type include(footer.php); and it will be added with the appropriate links. Of course now you will have to remove the script that adds the <embed> in your files, and replace everything with what i have.

Good luck!

eelix

Dstraction

12:37 pm on May 9, 2006 (gmt 0)

10+ Year Member



Thanks a ton for the code! I've been fiddling with this for awhile.

I'm brand new to php, so my first assumption is that the code in the box should be saved within a text editor to a file called footer.php. And I should be this file in the same folder on the server as my *.html is in.

If I am correct in these assumptions, then I must be screwing the 'include(footer.php);' line up because nothing is appearing on my *.html page. I've tried it many different ways and tried googling for the proper convention but I haven't had any luck yet.

I believe it to be something like this..

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

What is the exact call/include line? And if this is correct, are there any other reasons why the code isn't working?

Thanks again!

Joe

jatar_k

3:49 pm on May 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



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

would work as long as footer.php was located in the same directory as the file including it

otherwise you could put footer.php in the root directory of your site ad use this from any file within your site structure

<?php include $SERVER['DOCUMENT_ROOT'] . '/footer.php';?>

Dstraction

4:36 pm on May 9, 2006 (gmt 0)

10+ Year Member



I tried both ways and it still isn't working. Is there a good way to simplify the code and troubleshoot?

jatar_k

4:37 pm on May 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is it the code that isn't working or is it the include?

do you get errors?

eelixduppy

7:17 pm on May 9, 2006 (gmt 0)



Sorry...my code is missing a bracket

Revised footer.php


f($_GET[music] == 1)
{
echo "<script language='javascript'>
document.write(\"PAUSE&nbsp;&nbsp;<embed src=\"'+NFsong+'\" style='width:44px;height:26px' loop='true' >&nbsp;MUSIC\");
</script> ";
echo "<a href='$_SERVER[PHP_SELF]?music=0'>Stop music</a>";
}
else {
echo "<a href='$_SERVER[PHP_SELF]?music=1'>Play music</a>";
}

The above code should work properly now.

eelix

Dstraction

7:58 pm on May 9, 2006 (gmt 0)

10+ Year Member



I just tried the new code and I didn't notice a change.

I don't get any error messages. It simply doesn't do anything.

I have no idea whether it is the include or the code which is causing the problem.

Is there a very simple piece of code which I can 'include' to test whether the issue is with the code or the include?

Thanks for your help so far guys!

Joe

eelixduppy

8:51 pm on May 9, 2006 (gmt 0)



In your php file, add the following:
error_reporting(E_ALL);

This will show all errors and warnings in your script

eelix

Dstraction

10:22 pm on May 9, 2006 (gmt 0)

10+ Year Member



I appreciate all the help but I feel like I'm missing something.

I added the code to my footer.php file but where are the errors supposed to show themselves? The html file? It still isn't showing anything.

Another recap, to make sure I'm not missing anything:

1) The piece of code that you gave me should be saved in a file called 'footer.php'.

2) My *.html file should have an include file that says EXACTLY this:

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

3) Both files should be in the same folder on my server.

If all of this is correct, this is what I've already done. I've also tried putting the php file in my root and using the include line suggested by jatar_k - <?php include $SERVER['DOCUMENT_ROOT'] . '/footer.php';?>

It seems like this should be simple but I'm at a loss. Is there anything else that I could be missing? I've NEVER used php before so don't assume that I know even the basic conventions or procedures. Can you think of anything else that I may be leaving out or don't wrong?

jatar_k

11:31 pm on May 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when you view source on the page where your include is do you see the actual php code there?

maybe you can't use php in html files

eelixduppy

12:16 am on May 10, 2006 (gmt 0)




maybe you can't use php in html files

I don't think you can. Try changing all your files with the include() in it to *.php in order for the php to work correctly.

eelix

Dstraction

12:54 am on May 10, 2006 (gmt 0)

10+ Year Member



That isn't really possible because I use Miva Merchant as a shopping cart so many of my pages must have an html extensions. Is there an html counterpart to 'include' that will call php within an html document?

coopster

1:42 pm on May 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, they are called Server Side Includes (SSI). However, rather than go that route I would just setup your environment to parse .htm/.html files as PHP.