Using PHP to use same menu over 40+ pages

Discussion in 'PHP' started by dolalu, Feb 24, 2007.

  1. #1
    I have a website that uses the same navigation links on all of the 40+ pages.

    If i ever have to change one of the links i have to amend each 40+ pages individually.

    Im sure php can call a file so that you only have to change 1 file to update all 40+

    how do i do that?
    What do i need to do with the HTML files and what do i need to do in the PHP file i call from.

    If you use a PHP include in an html file does it automatically become a PHP file???

    Please help
    Dolalu
     
    dolalu, Feb 24, 2007 IP
  2. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    php.net/include
     
    Icheb, Feb 24, 2007 IP
  3. Synch

    Synch Peon

    Messages:
    76
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Create one php page that has all of your links then include/require that page in all the others

    example: Links.php
    
    <?php
    
    echo "
    <a href='http://mysite.com/link1.php'>Link 1</a>
    <a href='http://mysite.com/link2.php'>Link 2</a>
    <a href='http://mysite.com/link3.php'>Link 3</a>
    ";
    
    ?>
    
    PHP:
    index.php

    
    <?php
    include ('links.php');
    
    welcome to my site!
    
    ?>
    
    PHP:

    gallery.php

    
    <?php
    include ('links.php');
    
    Here are my pictures!
    ?>
    
    PHP:
    funstuff/arcade.php

    
    <?php
    include ('../links.php');
    
    Try out my arcade!
    ?>
    
    PHP:
     
    Synch, Feb 24, 2007 IP
    gemini181 likes this.
  4. Synch

    Synch Peon

    Messages:
    76
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no, but you could mod rewrite .html to be processed by php
    and if you wanted to be really tricky, make apache always include your links.php file before all other files.
     
    Synch, Feb 24, 2007 IP
  5. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #5
    Synch how would you get it to include the php files before and after every file?

    Thatd be great for me as currently i manually include my header and footer around every page.

    Does it cause extra load on the server, or will apache "remember" so will generally not impact performance.

    Thanks
     
    m0nkeymafia, Feb 25, 2007 IP
  6. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Search Google for auto_append_file and auto_prepend_file.
     
    Icheb, Feb 25, 2007 IP
  7. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #7
    cheers dude
     
    m0nkeymafia, Feb 25, 2007 IP
  8. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    #8
    include is the way to go in this case..

    <?php
    include ("mymenu.inc.php");
    ?>
    My page stuff
     
    Codythebest, Feb 25, 2007 IP
  9. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Reading the entire thread is the way to go in this case..
     
    Icheb, Feb 25, 2007 IP
  10. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #10
    In that case the post contained sarcasm :p
     
    m0nkeymafia, Feb 25, 2007 IP
  11. TwoToofs

    TwoToofs Active Member

    Messages:
    401
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #11
    I know this is an old post but I've been looking for this info for a week now. php makes my brain stop. Thanks
     
    TwoToofs, Apr 14, 2007 IP