SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    {$_server['document_root']}

    Hi there can anyone help here...

    I am trying to import my css file in my header which uses a browser detector and works fine in both ie and mozilla with this code:

    <style type="text/css" media="screen">
    <?php
    if ($browser == 'ns6') {
    echo '@import "includes/layout2.css";';
    } else {
    echo "@import \"{$_SERVER['DOCUMENT_ROOT']}/123/includes/layout1.css\";";
    }
    ?>
    </style>

    however i would like to now change to {$_SERVER['DOCUMENT_ROOT']} so that i can call it from sub directories but now only works in ie and not mozilla:

    <style type="text/css" media="screen">
    <?php
    if ($browser == 'ns6') {
    echo "@import \"{$_SERVER['DOCUMENT_ROOT']}/123/includes/layout2.css\";";
    } else {
    echo "@import \"{$_SERVER['DOCUMENT_ROOT']}/123/includes/layout1.css\";";
    }
    ?>
    </style>

    Please guys can someone help before i pull out all my hair...

    Cheers Garth

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_SERVER['DOCUMENT_ROOT'] is / as far as the site/html is concerned, i.e your code above is equivilent of:
    PHP Code:
    <style type="text/css" media="screen">
    <?php
    if ($browser == 'ns6') {
    echo 
    '@import "/123/includes/layout2.css";';
    } else {
    echo 
    '@import "/123/includes/layout1.css";';
    }
    ?>
    </style>

  3. #3
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So in theory then it should work right???

    It works fine in ie but mozilla will not read the ccs file although it reads all the include files using the same method...

    Cheers buddy

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And in Moz can you go directly to http://yoursite.com/123/includes/layout1.css ?

  5. #5
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So are you saying the i should type in the whole domain to reach the file?

    Do you know why it wont use the DOCUMENT_ROOT command to do the same thing.

    Cheers

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, i mean if you can't load http://yoursite.com/123/includes/layout1.css directly in the browser then something else is wrong. If you can load it directly then it narrows down where the problem might be, the direct loading in your moz browser is just a test

  7. #7
    SitePoint Evangelist Will Kelly's Avatar
    Join Date
    May 2005
    Location
    London
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_SERVER['DOCUMENT_ROOT'] gives the root path within your hosting environment (i.e. /domain.com/httpdocs/ ). That means it will include directories that would not be accessible when viewed from a clients pov (ie a browser). Do not include it, as said above just use preceeding / to start from the website root.

  8. #8
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so how do i include my css page if i got sub directories that require this file

  9. #9
    SitePoint Zealot
    Join Date
    Oct 2005
    Location
    Hegelsom, The Netherlands
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would use the '..' part, to get up a level

    This is an example doc structure:

    Code:
    [DIR] / 
       [FILE] file1.php
       [FILE] file2.css
       [DIR] /main/
          [FILE] file3.php
       [/DIR]
    [/DIR]
    To call /file2.css in the /main/file3.php file you'd use '../file2.css', that'll tell your browser to search for the file in the directory higher than the current one.

    Hope that helps.
    Yeap, I'm new here :P

    Game Insight

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I might have missed something but what about just using:

    $layout_1 = $_SERVER['HTTP_HOST'] . '/includes/layout1.css';

    to create a path to your css - then it doesn't matter where you call it from as it's an absolute path rather than relative so you don't need to worry about ../

    Then just: echo @import "$layout_1";


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
  •