SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER['DOCUMENT_ROOT' assistance

    Hi all,

    I am having a problem getting this to work.

    I have a basic menu set up using basic <li> tags for the layout, which i have saved in a menu.php file and i include it into the relevant place on the page, ie index.php

    There are no problem and the lnks in the menu work fine. Problem comes when I include the file in a page which is in a subdirectory of the root.

    I have tried using $_SERVER['DOCUMENT_ROOT' but just dont seem to get it to work.


    I thought this would work:

    PHP Code:
    <a href="<?php echo $_SERVER['DOCUMENT_ROOT'] ."/index.php"' ?>">Home</a></li>
    But it doesnt. I then tried creating a variable to hold the root info ie

    PHP Code:
    $root $_SERVER['DOCUMENT_ROOT']; ?> 
    and then use this in the link

    PHP Code:
    <a href="<?php echo '$root ."/index.php" ?>">Home</a></li>
    Not much luck with that either.

    I am obviously getting confused here, maybe with document root and server root.

    I was wondering if someone could point me in the right direction.

    Many Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What is the result of your tries? What does the link look like?

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    do the following:

    PHP Code:
    echo '<pre>';
    print_r($_SERVER);
    echo 
    '</pre>'
    and see which one you need
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing happens at all and when i run my mouse over the link it just displays the domain,

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    do the following:

    PHP Code:
    echo '<pre>';
    print_r($_SERVER);
    echo 
    '</pre>'
    and see which one you need
    this is the result from that - way over my head

    Code HTML4Strict:
    Array
    (
        [PATH] => /usr/local/bin:/usr/bin:/bin
        [UNIQUE_ID] => 4V6NmX8AAAEAAGpiJvUAAAB6
        [MvCONFIG_LIBRARY] => /usr/local/miva/lib/config/env.so
        [MvCONFIG_DIR_BUILTIN] => /usr/local/miva/lib/builtins
        [MvCONFIG_DIR_CA] => /usr/local/miva/certs
        [MvCONFIG_SSL_OPENSSL] => /usr/lib/libssl.so
        [MvCONFIG_SSL_CRYPTO] => /usr/lib/libcrypto.so
        [MvCONFIG_DIR_MIVA] => /home/sites/savemotorsport.com/public_html
        [MvCONFIG_DIR_DATA] => /home/sites/savemotorsport.com/mivadata
        [HTTP_ACCEPT] => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, application/x-shockwave-flash, */*
        [HTTP_ACCEPT_LANGUAGE] => en-gb
        [HTTP_UA_CPU] => x86
        [HTTP_ACCEPT_ENCODING] => gzip, deflate
        [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ;  Embedded Web Browser from: [url]http://bsalsa.com/;[/url] .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; InfoPath.2)
        [HTTP_HOST] => [url]www.savemotorsport.com[/url]
        [HTTP_CONNECTION] => Keep-Alive
        [SERVER_SIGNATURE] => Apache/2 Server at [url]www.savemotorsport.com[/url] Port 80
     
        [SERVER_SOFTWARE] => Apache/2
        [SERVER_NAME] => [url]www.savemotorsport.com[/url]
        [SERVER_ADDR] => 79.170.40.233
        [SERVER_PORT] => 80
        [REMOTE_ADDR] => 86.3.232.58
        [DOCUMENT_ROOT] => /home/sites/savemotorsport.com/public_html/
        [SERVER_ADMIN] => [email]webmaster@savemotorsport.com[/email]
        [SCRIPT_FILENAME] => /home/sites/savemotorsport.com/public_html/test.php
        [REMOTE_PORT] => 1389
        [GATEWAY_INTERFACE] => CGI/1.1
        [SERVER_PROTOCOL] => HTTP/1.1
        [REQUEST_METHOD] => GET
        [QUERY_STRING] => 
        [REQUEST_URI] => /test.php
        [SCRIPT_NAME] => /test.php
        [PHP_SELF] => /test.php
        [argv] => Array
            (
            )
     
        [argc] => 0
    )

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    just noticed your quotes may be wrong:

    PHP Code:

    <a href="<?php echo $root?>/index.php">Home</a></li>
    try that
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is what comes up when i rollover the link with the mouse

    http://www.savemotorsport.com/home/sites/savemotorsport.com/public_html//index.php

    this is using you suggested link above and the following at the top of the page

    PHP Code:
     <?php $root $_SERVER['DOCUMENT_ROOT']; ?>

  8. #8
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need to use DOCUMENT_ROOT at all -- thart's giving you the file system path, which you don't want in a link. Just make sure that in your navigation you include the complete path from the root. In other words don't just do:

    Code HTML4Strict:
    <a href="index.php">Home</a>

    but instead
    Code HTML4Strict:
    <a href="/index.php">Home</a>

    Then it will work no matter where you are in the directory structure. don't use relative links in global navigation!
    --
    Veronica Yuill
    Archetype IT

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that - but it doesnt seem to work, it makes the link point to the file taking from the directory I am in

  10. #10
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm. Can you post your revised code?
    --
    Veronica Yuill
    Archetype IT

  11. #11
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its the same as you just posted

    <a href="/index.php">Home</a>

    I think I read while I have been searching on this that the / part only works in html files and not php ones

  12. #12
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok veronicay,

    you may call me several names, most of which should revolve around me being slightly thicker than my mams gravy.

    It seems it is more helpful for me to actually upload the correct file.

    Feeling rather stooooopid

  13. #13
    SitePoint Zealot
    Join Date
    Oct 1999
    Location
    France
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL, we've all been there
    --
    Veronica Yuill
    Archetype IT


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
  •