SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast am_dorky's Avatar
    Join Date
    Sep 2008
    Location
    Bucks
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ../path/to/file.inc backwards trailing

    Hi Guys,

    I'm having a really stupid problem and am totally lost. Have checked out other threads relating to this but not really understanding what changes I need to make to get this sorted.

    my site has a folder layout as:

    site (folder)
    admin (folder)
    filename1.inc

    design (folder)
    header.inc
    footer.inc


    In filename1.inc I am trying to INCLUDE the header and footer files (below) but am getting a FUNCTION INCLUDE WARNING.

    include("../design/header.inc");
    include("../design/footer.inc");

    I thought by including ../ this goes back one folder but due to this not working I'm assuming I'm wrong.

    I read on another thread about making changes to php.ini but wasn't sure what I would need to change.

    Any ideas?

    Many Thanks in advance!

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you clarify your direction structure? It's pretty ambiguous on what belongs to what.

    Is this what you mean?

    Code:
    site/ (folder)
        admin/ (folder)
            filename1.inc
        design/ (folder)
            header.inc
            footer.inc
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Enthusiast am_dorky's Avatar
    Join Date
    Sep 2008
    Location
    Bucks
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bhanson View Post
    Can you clarify your direction structure? It's pretty ambiguous on what belongs to what.

    Is this what you mean?

    Code:
    site/ (folder)
        admin/ (folder)
            filename1.inc
        design/ (folder)
            header.inc
            footer.inc
    Sorry... you have got it spot on with what I mean.

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And can you paste the error message?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should use php extensions for your include files, especially if they are under your web root

  6. #6
    SitePoint Enthusiast am_dorky's Avatar
    Join Date
    Sep 2008
    Location
    Bucks
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    You should use php extensions for your include files, especially if they are under your web root
    Stormrider - why do I need to use the php extensions? My .inc files just have html in them. Is it just good practice?

    I seem to have resolved the problem I had now anyways. Not sure how. Think I was missing a letter in my path name.

  7. #7
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by am_dorky View Post
    Stormrider - why do I need to use the php extensions? My .inc files just have html in them. Is it just good practice?
    Yes, it is considered good practice. Even if now they're nothing more than HTML; if later you (or someone who maintains a project after you) wants to add some PHP code to the included files then they don't have to worry about renaming the files, looking for all references to them and adding php extensions in order to prevent people from seeing the code by navigating directly to an inc file.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Exactly, it's just good practice, and 'future proof'.

  9. #9
    SitePoint Enthusiast am_dorky's Avatar
    Join Date
    Sep 2008
    Location
    Bucks
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Of course, that makes sense. Thanks guys

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'd like to add that you should avoid having include files in your webroot even if they are php extension.

    first reason is because if the include file does something that relies on other files, a request to /header.php might do "half something" and could be bad in some cases.

    second reason is that if you have display_errors set to On in your php.ini, the file might spit out an error if it is not used the way the application intended.

    i suggest you have only one include file, which contains nothing much more than defines and perhaps the __autoload() special function. all other files should be in a higher directory:

    common.php
    PHP Code:
    <?php

    // Global defines
    define('SYS_DIR''/home/user/sys/');
    define('APP_DIR''/home/user/app/');
    define('TEMPLATE_DIR'APP_DIR.'templates/');
    define('WWW_DIR''home/user/public_html/');

    ?>
    and if you want to include a file, do something like:

    PHP Code:
    include(TEMPLATE_DIR.'header.tpl'); 


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
  •