+ Reply to Thread
Results 1 to 7 of 7

Thread: Regarding - Splitting PHP Files into Includes

  1. #1
    TofuBoy's Avatar
    TofuBoy is offline x10Hosting Member TofuBoy is an unknown quantity at this point
    Join Date
    Jan 2009
    Location
    In the middle of a piece of Tofu
    Posts
    9

    Regarding - Splitting PHP Files into Includes

    Can someone give me a list of files to split into? I want to keep the files compact by using includes. I don't know if header.php and footer.php would be good files to split.

    header.php - Contains tags between <html> and </head>

    footer.php - Contains the copyright and from </body> to </html>

    -------

    And the navbar:
    navbar.php - Contains the navbar HREFs
    Last edited by TofuBoy; 04-06-2009 at 10:04 AM.

    Ignore the free V.I.P. thing because I don't have a forum yet. :nuts:

  2. #2
    Parsa44 is offline x10 Sophmore Parsa44 is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    232

    Re: Regarding - Splitting PHP Files into Includes

    I cant get include() or require() to work on x10hosting at the moment.
    If anybody could help me...

  3. #3
    wjh2303 is offline x10 Sophmore wjh2303 is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    139

    Re: Regarding - Splitting PHP Files into Includes

    @ tofuboy
    Having a header and footer include files seems to work fairly well for me, and it was recomended to me by someone else on this forum, so its likely an accepted if not recomeded way to do things

    @parsa
    works fine for me, post a sample of the code you're using, maybe you have a simple syntax error or the like

  4. #4
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    Re: Regarding - Splitting PHP Files into Includes

    @TofuBoy
    i generally use one config file and use it to set variables for my separate parts, like this:

    html page
    HTML Code:
    <?php
    include('config.php');
    ?>
    <!DOCTYPE blah...>
    <head>
    <?php echo $headCode; ?>
    </head>
    config.php
    PHP Code:
    <?php
    $headCode 
    '<title>This is where your code goes.</title>';

    etc...
    ?>

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Regarding - Splitting PHP Files into Includes

    I've read somewhere that it is the best coding practice to keep any function 50 lines or less (excluding comments and long strings). So, it would be best to use many small functions instead of one huge function. This just makes your code easier to understand to you and for anyone who may need to look at it in the future.

    It is also good to group functions that are often used together into the same file, so they are all included at once. Headers and Footers are used on every page, every time, so really, you could put them in the same file and save yourself a few keystrokes and probably a few processor cycles here and there. It doesn't make a lot of sense to put
    Code:
    include('header.php');
    include('footer.php');
    In every file when you could just say
    Code:
    include('whatever.php');
    An exception would be if your code does not have a function. If your header is always the exact same thing, you don't need a function. Just put the code in the file then call header.php when you want the header output. Here, it makes more sense to separate them, since there's something in between the header and footer, presumably :P
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  6. #6
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: Regarding - Splitting PHP Files into Includes

    For me, I split configuration, frequently used functions, and my mysql connect's into them.


    The mysql-connection's a big one though - include("logmein_admin.php") or include("logmein.php"), depending if it needs all permissions, or just select.

    The reason it's a big one? Locally, the password and username are different. So x10's got a different logmein and logmein_admin than localhost.

    I don't have to change my code to make it work on x10


    If anything, I'd store mysql username/passwords in an include, then bury it in a folder with a .htaccess "Deny From All" setting. Seems include and require CAN access folders that have been set to "deny from all," which makes it handy - index.php can include includes/logmein_admin.php, but there's no way to actually access logmein_admin.php directly ^_^


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  7. #7
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: Regarding - Splitting PHP Files into Includes

    I always use includes for headers and footers and yes, it is an accepted way of doing things.

    I think your have to have an intermediate account for includes to work though which is why you might be having problems.

+ Reply to Thread

Similar Threads

  1. Parsing html files for php - .htaccess?
    By onyxmoron in forum Free Hosting
    Replies: 0
    Last Post: 01-06-2009, 03:01 AM
  2. Root PHP files not getting executed
    By cool_dude_99 in forum Free Hosting
    Replies: 3
    Last Post: 05-09-2008, 09:53 PM
  3. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  4. Rewritten PHP Includes tutorial
    By [XiRE] in forum Tutorials
    Replies: 2
    Last Post: 07-28-2006, 10:19 AM
  5. I need php code for downloading zip files from my site !!
    By careerbridge in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 07-16-2006, 12:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers