Results 1 to 2 of 2

Thread: PHP: How to set $_SERVER['DOCUMENT_ROOT']

  1. #1
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 23 Times in 23 Posts

    Default PHP: How to set $_SERVER['DOCUMENT_ROOT']

    Another code snippet for you all. I like to use the DOCUMENT_ROOT variable in my scripts, it is as if nothing else is ever quite as useful. Unfortunately here at redfox the variable is currently not set, which can be frustraiting.

    Stick this tiny bit of code so that it is one of the first things parsed, and it will set the variable for you, regardless of where the file resides, so you can use it again throughout your program.

    There might be occasions where this will break down, but so far I don't know of any.

    PHP Code:
    /**
     * On Some PHP installations the Document Root variable is not set, here we
     * quickly check, and if it is not already, set the variable.
     */
    if( !isset($_SERVER['DOCUMENT_ROOT']) ) {
        
    $_SERVER['DOCUMENT_ROOT'] = str_replace($_SERVER['SCRIPT_NAME'],'',
                                 
    str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']));


  2. #2
    Join Date
    Feb 2004
    Posts
    4,877
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    This is good to see - these scripts will definatly come in handy!
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. "String reference not set to " - Encrytion
    By jaimalchohan in forum ASP.NET
    Replies: 3
    Last Post: 28th November 2005, 08:15 PM
  2. How to set up a temporary url?
    By RobvK in forum Technical Support
    Replies: 5
    Last Post: 4th September 2005, 06:01 PM
  3. Can you set adomain to a alias folder?
    By dv8host in forum Technical Support
    Replies: 3
    Last Post: 30th August 2005, 03:20 PM

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
  •