Web Hosting Forums

Results 1 to 3 of 3

This is a discussion on Adding extra include folders in the Hosting Talk & Chit-chat forum
Hi all, (or should that be 'Hi Jason' ) I'd like to add some non-web directories to my PHP include path. Like home/myaccount/bin. How do ...

  1. #1
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570

    Adding extra include folders

    Hi all, (or should that be 'Hi Jason' )

    I'd like to add some non-web directories to my PHP include path. Like home/myaccount/bin. How do I do that?

    I've read about using htppd.conf and htaccess files, but all vague and with 'but your host needs to allow it' in the description. Does anyone have a solid 'How to do it here at JAG' for me?

    And a second question: is there a way to include a tree a once (i.e. include not just 'bin' but all subdirs of bin too)?

    Regards,

    Wim Heemskerk

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884

    Re: Adding extra include folders

    Originally posted by Gwaihir
    Hi all, (or should that be 'Hi Jason' )
    LOL! I guess I answer too many questions around here...

    To add additional paths to your include path, just create a file named .htaccess (if it isn't there already) in your public_html directory and add the following:

    php_value include_path .:/usr/share/php:/your/dir/here

    Just add all of the directories you want to include, separated by colons. Be sure to keep the first two (. and /usr/share/php) as is--"dot" is your current directory and /usr/share/php contains some standared libraries (such as PEAR) that some scripts may want to use.

    The include path will not automatically search subdirs. It will append the each of the dirs you specify to the begining of the path you use in you Include(), file(), require(), fopen(), etc., etc. call in the order that you specify those paths in. So if you include("myfile.inc"), PHP will try to open the file in this order:

    1. ./myfile.inc
    2. /usr/share/php/myfile.inc
    3. /your/dir/here/myfile.inc

    It will try each path until it finds a match. Likewise, if you include("subdir/myfile.inc"), PHP will try to open

    1. ./subdir/myfile.inc
    2. /usr/share/php/subdir/myfile.inc
    ... (you get the idea)

    So if you have several subfolders in /home/username/phpinc, you can specify /home/username/phpinc in your include_path and then make include() calls with suba/file.inc, subb/file.inc, etc.

    Finally, you can specify a full path to your include file and PHP will bypass whatever you have set in your include_path. (This is the fastest way to do things, by the way.)

    include("/home/username/phpinc/file.inc");

    Hope this helps...

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    Thanks Jason,

    Finally found time to implement this today.

    I know the third method may work fastest, but I specifically wanted to avoid that to keep my includes a bit more 'hidden', for example in case the php processor failed at some point.

    Still I doubt if it's possibility to effectively hide the includes in such a multi user environment: anyone in the SSH shell on the same host could access the htaccess file, don't you think?
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

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
  •