SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast weich1213's Avatar
    Join Date
    Nov 2008
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about using a configuration file for includes

    I'm trying to use an include that is a configuration file for the other includes so I could put it in front of my includes and not have to worry about putting periods ,and having to figure out how many, before the other includes on the page. Here's my configuration include:

    <?php

    $serverPath =$_SERVER['DOCUMENT_ROOT']; // down to wwwroot
    $folderPath = ""; //the folders below wwwroot - home page location
    $fullPath = $serverPath.$folderPath; // the full path
    $includesPath = $fullPath."_includes/";
    ?>

    and on my page I put the following:


    <?php
    include "../_includes/config.inc.php4";
    include $includesPath."page_bottom.inc.php4";
    ?>

    Unfortunately, this does not work for any of my includes. I got the idea from a book and I don't know why it's not working. I don't know much php, can anyone tell me what I'm doing incorrectly? Thanks a lot, WEich1213

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Do you mean that you don't want to have to work out the page's location in relation to the included file? You can just use this throughout your site, as it works on any page:

    PHP Code:
    <?php include $_SERVER["DOCUMENT_ROOT"] . "/includes/file.php"?>
    (where file.php is the name of whatever file is being included).

    PS Did you get your example from Codin' for the Web? It suggests what you have done above, but it is a long-winded solution, nowhere near as simple as the one above.

  3. #3
    SitePoint Enthusiast weich1213's Avatar
    Join Date
    Nov 2008
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also do this in the highest level include --
    PHP Code:
    DEFINE('root'$_SERVER['DOCUMENT_ROOT']); 
    Then you only need do do like..
    PHP Code:
    echo '<a href="'.root.'"/test.php">test</a>'


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
  •