Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Difficulty setting include path from .htaccess

    In PHP 5.2.5, using Apache 2.2.17, I'm trying to set the include path through the .htaccess file. It's not working, and I don't see the reason.

    There is already a .htaccess file in my application's root directory. (That is, in the directory where the application's directory tree begins; this is the same as Apache's document tree root on my client's QA system, but not on my development system.) I added this line to it:

    php_value include_path "/"

    In other words, I want PHP to search for includes in the document root directory, no matter where this script was loaded from.

    My includes actually take this form:

    include "include/constants.php";

    Which was originally intended to load ./include/constants.php (relative to the directory containing the script). After I have set include_path, this statement should load /include/constants.php instead.

    If I call get_include_path, I get "/". If I change the include_path setting to "/xxx" (a non-existent path), get_include_path returns "/xxx". It appears that the include path is being set properly.

    But the include statement continues to load a file relative to the directory that contains the script, no matter what I have set include_path to. (I determined this by storing a different version of the included file in every directory, and figuring out which version got loaded. When include_path is set to /xxx the include shouldn't work at all; it does.)

    It seems to me that there must be something in PHP's universe that makes it ignore the value of include_path, but I haven't found it. Does anyone know what is going on here?

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,168
    Thanks
    47
    Thanked 978 Times in 908 Posts
    Maybe the include path is only used if you don't have a path in the load line? Try it with just the file name.

    include "constants.php";

    cheers, Paul

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    No, sadly, that made no difference. (Well, fortunately, not sadly. If that were the problem it would make the feature useless to me. Since the problem is something else, there's still hope.)

  4. #4
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    With the help of a nice person in another forum, I figured it out.

    include_path is a file path, not a document path. When I set include_path to "/" I wasn't pointing to the root of the document space; I was pointing to the root of the default drive!

    From there, everything played out according to the rules. When I specified a relative path in the include statement, PHP ignored include_path (you were right about that.) When I specified a filename alone, PHP looked for the include file in the default drive's root directory, then in the directory that contained the script and in the current working directory (in my case, the same), and it didn't find the file in any of those places.

    When I defined include_path correctly, everything worked.

  5. #5
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,168
    Thanks
    47
    Thanked 978 Times in 908 Posts
    Real paths, ugly!

    cheers, Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •