Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problems with $_SERVER["DOCUMENT_ROOT"] in a Subdirectory.

    Hey, I have a quick question. I've having some problems while working in a subdirectory and using the "DOCUMENT_ROOT" command.

    I have a subdirectory (i.e. "http://sub.mysite.com") and when I use a "$_SERVER["DOCUMENT_ROOT"]" in one of the pages (such as "http://sub.mysite.com/dir/content.php") to load, say, a header, the PHP parser recognizes this call as being to "http://mysite.com" instead of the subdirectory from where it is being called.

    One method I have used to get around this problem is to use the code "$_SERVER["DOCUMENT_ROOT"].sub" when I write that statement and everything works fine. However, this is quite inconvenient for my site style layout and I'm wondering if PHP has and tricks in it for dealing with and traversing subdirectories.

    Another method that I have found that works is to use "$_SERVER["SUBDOMAIN_DOCUMENT_ROOT"]", though this is also inconvenient. So, my question is..can PHP work inside subdirectories using default commands like DOCUMENT_ROOT whilst in a subdirectory?

    Thanks for your help. =)
    -Patrick

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could modify Document_Root with htaccess to suit to your needs
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could modify Document_Root with htaccess to suit to your needs
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question .htaccess

    Quote Originally Posted by gunman View Post
    You could modify Document_Root with htaccess to suit to your needs
    Where and how would I do that? Thanks for your replies.

    I've heard about and even used .htaccess in the past, but never really kept using it as I found out about PHP and coded my own login page that way. So how would .htaccess be used then?

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Note the difference between subdomains and subdirectories...
    sub.domain.com , is a subdomain
    www.domain.com/dir/ or sub.domain.com/dir/ are both subdirectories of the root folder of subdomain (www is just another subdomain)

    your DOCUMENT_ROOT should be a filepath /home/httpd/etc/etc it should have nothing to do with http://etc , its hard to answer your question since different hosts handle subdomains in different ways, some control panels create the subdomain as a subdirectory of the root domain, others in a separate directory altogether.

    If SUBDOMAIN_DOCUMENT_ROOT is available then I would have thought that would be the answer (assuming it is also set when in the www subdomain)

    you could also perhaps look at getpwd() etc to find out where you are in the filesystem and work it out from there.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    I am having a similar issue with a pre-built php script that uses "$_SERVER["DOCUMENT_ROOT"]" to include files.

    My server panel configures subdomains as a subdirectory of the root, and as a result the document_root of the subdomain resolves to the main url document_root.

    I cannot change the php script and the developper tells me that I need to get my subdomain configured as a seperate directory so that the references to include files with "$_SERVER["DOCUMENT_ROOT"]" will find files when installed in the subdomain.

    Instead of changing server setup, how do I get the subdomain DOCUMENT_ROOT to point to the subdomain base directory in .htaccess so that the script can find all include files ?

    Can I do the same with SITE_HTMLROOT if at all possible in .htaccess ?

    Thank You

    Louis


  •  

    Posting Permissions

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