Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts

    questions on remote php source files (include)

    A little while ago, the nice helpful people here on cf told me about

    Code:
    <?php include $_SERVER['DOCUMENT_ROOT'] . '/footer.php'; ?>
    And I've used it sparingly, pretty much just for my page header (banner, menu links) and footer.


    Some questions I have though, are where should I begin and where should I stop?
    Are there any things that won't function correctly if aren't on the actual index.php file?
    Could I put the meta tags and things inside a remote php file? Would it cause problems if I even put the <html> opening tag into the remote php file?

    Right now my codes a little messy, so I'm trying to 'clean as I go', and keep things organized, so it won't be as hard to go back and tidy things up when I have the spare time

    Are there any down sides to having multiple remote files?
    (side column in one, header in one, footer in one)
    Or is it better to have all of the data in 1 file?

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    There is no drawback at all to having different slices of your HTML code in different PHP files that are included into the main file. In fact, this is exactly how CMS systems work. If you get curious, open up a copy of Wordpress some day and take a look.

    Feel free to chop up your page into as many sections as you want. When you put it all together with includes the end user won't have any clue of how it got there and it will work as you intended.

    You could theoretically put every single character of the page's HTML into different files and included them one-by-one into your index.php page and it wouldn't hurt a thing.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    133
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks

    Sounds like a fun idea lol.

  • #4
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    If you really want to see how efficient it can be to chop up pages into multiple files checkout the Model View Controller (MVC) setup. Its much more sophisticated than simply calling in your header and footer files on each page manually. The MVC will make your site truely dynamic and easy to update in the future.

    Basically it starts with the controller (a switch statment) that reads the current url and changes the files to be included into the page based on the url. Its really not that bad to understand, just watch some video tutorials on developing one and you should get it.

    Also the MVC is the perfect place to get rid of that tacky .php or.html ending on your url. In fact you can get that url to spit out basically whatever you want it to regardless of the file names being called.

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts
    standard method for assembling php pages;
    index.php in root

    create a plugins folder ....
    plugin/plugin_pages.php

    include the pages with this code

    Code:
    <?php include 'plugin/plugin_pages.php;' ?>


  •  

    Posting Permissions

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