SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use PHP set_include_path?

    I have setup an Apache server on a Windows XP machine. I would like to have the files I create work on both the XAMPP setup on my Windows XP machine and also work on the live website.

    I tried to have my index.php use this:

    <?php set_include_path('/include'); ?>
    and
    <?php set_include_path('/include'.PATH_SEPERATOR.get_include_path()); ?>

    All my include files are in the /include folder off the root for the site.

    Then I tried to use <?php include "footer.php" ?> but the file is not found.

    What am I doing wrong.
    Each day is a learning experience.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    Your /include should be the full path like c:/path/to/htdocs/include or relative to the script like ./include (note the dot). You're almost there.
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imho the easiest option is to not specify an include path in your php.ini or php script and just specify the path (full or relative) in the include(). If you don't specify a path, include will look for the file in the directory of the script that called the include().

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the past, I have used <?php include($_SERVER['DOCUMENT_ROOT']."/include/footer.php") ?> from anywhere on the site. So even if I were somewhere like root/sub/sub/sub/fiile.php, that command would get to the root/include folder.

    So maybe there is something else I need to do. I think DOCUMENT_ROOT takes me to the root of the site, and at home that is the htdocs folder which is one level up from the mysite folder or the daughers_site folder. The ides is that I would have:
    htdocs/mysite01
    htdocs/mysite02
    htdocs/mysite03
    etc.

    What are my options?

    So DOCUMENT_ROOT does not work from the sub folder. The only folder that I use like that is the include folder.
    Each day is a learning experience.

  5. #5
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CSU-Bill View Post
    What are my options?
    what I always do is not specify an include_path anywhere and then simply specify the relative path from the current directory on the website to the include file.

    the relative path will always start with ./ or ../


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
  •