Need PHP Include Help

Discussion in 'PHP' started by BlueEew, Jan 26, 2008.

  1. #1
    Hey, I have a website that as been waiting a long time to be added to the Internet. However I have been delayed, and delayed. Now I have the layout ready and coded I have come across one more problem.

    I need to add PHP Includes so I can edit the whole website like the menu ect from one file. I used to use SSI, and when I tried to use it. It did not work. I am need in help as soon as possible. If anyone is willing to help.

    Thanks,
    BlueEew.
     
    BlueEew, Jan 26, 2008 IP
  2. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put your menu html code in a file and give it a name like menu.php

    In the pages where you want the menu to appear use this code replacing the old menu html:
    <?PHP include("menu.php"); ?>
    PHP:
    This assumes your website pages are .php and the menu.php is in the same directory as the page(s)
     
    Gawk, Jan 26, 2008 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    And if it is not in the same directory just add directory/ in front of the file name.

    If it happens to be up (back) one level add ../ in front of the filename.

    You can also use abosolute server path but that can get messy.
     
    Colbyt, Jan 26, 2008 IP
  4. BlueEew

    BlueEew Well-Known Member

    Messages:
    2,434
    Likes Received:
    79
    Best Answers:
    1
    Trophy Points:
    150
    #4
    The webpages are in the .html format, so how would I do it like that?

    Change the "menu.php" in the PHP script to "menu.html"?
     
    BlueEew, Jan 26, 2008 IP
  5. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need to change all your .html pages to .php - this also means changing the internal links to point to the .php pages instead of the .html

    Make a backup of your site, put it in a test directory and rename the webpages to .php - this will allow you to test it all and when you are happy copy them to the main site.
     
    Gawk, Jan 26, 2008 IP
  6. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #6
    You can also declare that html pages are to be parsed as php in the .htaccess file. The exact syntax escapes me at the moment.

    One thing you do not want to do is have <head> or <body> tags on the pages that are to be included. Most browsers will render it correctly but it not the right way to it.
     
    Colbyt, Jan 26, 2008 IP
  7. BlueEew

    BlueEew Well-Known Member

    Messages:
    2,434
    Likes Received:
    79
    Best Answers:
    1
    Trophy Points:
    150
    #7
    Thanks a lot guys and gals, that was quite easy with your help. Its a good job that I have not yet started adding the pages yet. :) Thanks again.
     
    BlueEew, Jan 26, 2008 IP