SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    different linked files in same php include?

    Hello,

    Thinking there must be some way to do this. Some conditional php statement? I put my flash menu in a php include. Although I just realized, that each page has its own linked .swf menu/file (e.g. home.swf, aboutus.swf, etc). Each has its own accompanying .swf in order to show the current page in the menu. So... its there some magic way to call each different .swf file depending on the page selected? Or do I just have to take it out of the include? Thanks!

    So here is the flash link in the include...

    Code:
    <param name="movie" value="aboutus.swf">

  2. #2
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this:
    PHP Code:
    <?php

    switch($_SERVER['REQUEST_URI'])
    {
        case 
    'index.php':
            
    $swf 'home.swf';
            break;
        case 
    'about.php':
            
    $swf 'aboutus.swf';
            break;
        
    // etc
    }

    ?>
    <param name="movie" value="<?php echo $swf?>">
    or more concise:

    PHP Code:
    <?php

    $swfMap 
    = array(    '/index.php' => 'home.swf',
                        
    '/about.php' => 'aboutus.swf'
                        
    // etc
    );
    $swf = (array_key_exists($_SERVER['REQUEST_URI'], $swfMap)) ? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';

    ?>
    <param name="movie" value="<?php echo $swf?>">
    aaron-fisher.com - PHP articles and more

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Cool! Thank you very much. So I could just put that PHP statement in the include and above the embed code right? And that looks like it should work fine with the same include in different directories right? Or only the second one (because of the forward slash)?

  4. #4
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Cool! Thank you very much. So I could just put that PHP statement in the include and above the embed code right? And that looks like it should work fine with the same include in different directories right? Or only the second one (because of the forward slash)?
    Yes the directory you put the include in won't matter. Just add/change the paths to match whatever $_SERVER['REQUEST_URI'] happens to be for each page. If you are going to put that into an include I would wrap it into a function to avoid polluting the global space, i.e. put something like this in your include:

    PHP Code:
    <?php

    function getFlashMenuForPage()
    {
        
    $swfMap = array(    '/index.php' => 'home.swf',
                            
    '/about.php' => 'aboutus.swf'
                            
    // etc
        
    );
        return (
    array_key_exists($_SERVER['REQUEST_URI'], $swfMap)) ? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';

    ?>
    then you can call it by:

    PHP Code:
    <param name="movie" value="<?php echo getFlashMenuForPage(); ?>">
    aaron-fisher.com - PHP articles and more

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Nice! Out of curiosity, how do you mean? "pollute global space"? Like white space?

  6. #6
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Nice! Out of curiosity, how do you mean? "pollute global space"? Like white space?
    If you assign a variable outside of a function or a class, it has global scope. So in that example we declare an $swf variable. Now say you include that file, but then include a bunch of other files and one of them has an $swf variable. The former value of $swf would be overwritten. Wrapping it in a function protects that from happening.
    aaron-fisher.com - PHP articles and more

  7. #7
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Ahhh. Ok thank you very much. Have a good one!

  8. #8
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    OK I was finally just able to fully test these. Unfortunately none of them worked. The function one throws an error. And the other two just land on home.swf each time. Any ideas? Thanks!

  9. #9
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I left out a closing } in the function - you'll need to add that. You'll also need to modify the $swfMap array to match your urls and flash file names. Beyond that you'll have to post your code.
    aaron-fisher.com - PHP articles and more

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Here is the code from the include. Just tested it. This was in my aboutus.html page but it's showing the home.swf menu. All the names are correct. What do you think?

    Also, whats this bit doing? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf'; Thanks!

    Code:
    <?php
    
    function getFlashMenuForPage()
    {
        $swfMap = array(    '/index.php' => 'home.swf',
                            '/aboutus.php' => 'aboutus.swf'
                            // etc
        );
        return (array_key_exists($_SERVER['REQUEST_URI'], $swfMap)) ? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';
    }
    ?>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="250" height="400">
    			<param name="movie" value="<?php echo getFlashMenuForPage(); ?>">
    			<param name="wmode" value="opaque">
    			<!--[if !IE]>-->
    			<object type="application/x-shockwave-flash" data="<?php echo getFlashMenuForPage(); ?>" width="250" height="400">
    			<param name="wmode" value="opaque">
    			<!--<![endif]-->
    				alt content
    			<!--[if !IE]>-->
    			</object>
    			<!--<![endif]-->
    			</object>

  11. #11
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Here is the code from the include. Just tested it. This was in my aboutus.html page but it's showing the home.swf menu. All the names are correct. What do you think?
    As I alluded to, you will need to change the $swfMap array to match your urls. So the first array item is:
    Code:
    '/index.php' => 'home.swf'
    you'll need to alter the '/index.php' to whatever $_SERVER['REQUEST_URI'] equals for the given page. not sure what it should be? Put
    PHP Code:
    echo $_SERVER['REQUEST_URI']; 
    at the top of the page in question and copy/paste that.



    Quote Originally Posted by EricWatson View Post
    Also, whats this bit doing?
    $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';
    That makes the default .swf file ''home.swf' in case $_SERVER['REQUEST_URI'] does not match anything in the array. Which is probably the case right now because you haven't customized it to your needs yet.
    aaron-fisher.com - PHP articles and more

  12. #12
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Oh god. Can't believe I missed that. I of course thought the names were correct. However they're not .php extensions. They're .html extensions. Ok I'll edit that and I'm sure it will work. Thanks for your patients. I'll post back with my progress.

  13. #13
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    OK. That works absolutely perfect now. Thank you very much for the awesome solution!

    Quick question? Since I know nothing of this inner workings... This will work in all browsers right? And do you think it slows anything down - or is that just instantaneous just like a direct link would be?

  14. #14
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    ...also. I have ten other pages that all use the same swf. Do I have to state each ten times? Or is there some trick were I can get away saying it once?

  15. #15
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    maaan! I'm unfortunately stuck again. In my pages in sub folders I get errors.

    I get this error. Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/building/public_html/inc/nav.inc on line 6

    I'm running this code.
    <?php
    function swf()
    {
    $swfMap = array(
    '/index.html' => 'home.swf',
    '/aboutus.html' => 'aboutus.swf'
    '/popup/parents1.html' => '/popup/parents-inner.swf' // line 6
    // etc
    );
    return (array_key_exists($_SERVER['REQUEST_URI'], $swfMap)) ? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';
    }
    ?>

    How can I call the sub folder links within this same include? feeeken path question. I'm embarrassed. But I tried everything.

  16. #16
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Scratch my last path question. Im retarded and was missing a cama. I blame it on the include (.inc) has no code highlighting. So I just have the two remaining quick questions then...

    1) Since I know nothing of this inner workings... This will work in all browsers right? And do you think it slows anything down - or is that just instantaneous just like a direct link would be?

    2) I have ten other pages that all use the same swf. Do I have to state each ten times? Or is there some trick were I can get away saying it once?

    Thanks!

  17. #17
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    1) Since I know nothing of this inner workings... This will work in all browsers right? And do you think it slows anything down - or is that just instantaneous just like a direct link would be?
    PHP runs on the server so it is not subject to browser issues. Slowness is definitely not even a remote concern with that little snippet of code.

    Quote Originally Posted by EricWatson View Post
    2) I have ten other pages that all use the same swf. Do I have to state each ten times? Or is there some trick were I can get away saying it once?
    On this line:

    return (array_key_exists($_SERVER['REQUEST_URI'], $swfMap)) ? $swfMap[$_SERVER['REQUEST_URI']] : 'home.swf';

    'home.swf' is the default if no match is found in the array. so you could change that to the swf that is on the majority of your pages and make that the default.
    aaron-fisher.com - PHP articles and more

  18. #18
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    That's a good idea. Thanks a ton aamonkey I owe you one. Take care!

  19. #19
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Alright aamonkey I got one more for you. I think this will be the last. In my sub folder (the one needing the same swf x 10) there is a swf called inner.swf. Now I know why it was used. Because it's links are relative. Meaning it's links only point to out of the sub folder and all the swfs in the root only point the opposite. In other words there is no default swf that will link to all the pages (root and sub folders). So the default swf (currently home.swf) is of no use. So how would that same PHP snippet look without the fallback swf? I could probably play with it but I'd rather get it from you and know it's fullproof. Thanks again!

  20. #20
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Scratch another one. I figured it out. I used the same code and figured out how to make all the paths work.

  21. #21
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Sorry to drag this out. What about the path to the strait domain (without index.html)? Should it simply look like this? Unrelated I changed the swf to index.swf.

    '/' => 'index.swf',


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •