SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using server variables in php_value

    Hi,

    I'm working on a system that uses auto_prepend_file to include a global config file. I sometimes work in a different location, where the files are in a different place. Furthermore, I would like the project to be flexible, and easy to install in a directory structure of the user's choice.

    Therefore, I would to use the server variable DOCUMENT_ROOT in the php_value. Something like this;

    Code:
    php_value auto_prepend_file %{DOCUMENT_ROOT}/myproject/config.php
    Is this possible at all?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Ize,

    I don't see what's wrong with it - except that you could remove %{DOCUMENT_ROOT} with the same effect (and it would be more correct, i.e., have a better chance of working).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm that's odd.. PHP gives me this fatal error with that line:

    Code:
    Fatal error: Unknown: Failed opening required '%{DOCUMENT_ROOT}/path/to/inc.php'
    In other words, the DOCUMENT_ROOT variable is not translated to the actual document-root.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Ize,

    Okay, then definitely REMOVE the %{DOCUMENT_ROOT) from the code. Remember, this is a web server so the leading / IS the DocumentRoot!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is a wicked old thread, but it mislead me before, so here goes:

    You cannot use a path relative to the DocumentRoot in an .htaccess file. However, you can use a file relative to the ServerRoot. This doesn't really help the original poster, but hey, "Nope" is an answer too.
    Matt Alexander
    Alexander Site Design

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    I'm not sure why I was blind to the obvious two+ years ago but %{DOCUMENT_ROOT} is a "server internal" variable so $_SERVER['DOCUMENT_ROOT'] would be how PHP would access that value.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    I'm not sure why I was blind to the obvious two+ years ago but %{DOCUMENT_ROOT} is a "server internal" variable so $_SERVER['DOCUMENT_ROOT'] would be how PHP would access that value.

    Regards,

    DK
    Yes, but the OP was calling php_value, which is Apache syntax, not PHP.
    Matt Alexander
    Alexander Site Design


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
  •