Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7739765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:36:14+00:00 2026-06-01T08:36:14+00:00

I use $_SERVER[DOCUMENT_ROOT] a lot to make sure that all my links will work

  • 0

I use $_SERVER[DOCUMENT_ROOT] a lot to make sure that all my links will work properly. For instance:

<link href="' . $_SERVER[DOCUMENT_ROOT] . '/favicon.ico" rel="icon" />

It doesn’t matter the actual path of the file that’s in, it will always find the correct location of the favicon relative to the document root.

This all works as expected on my web server. However, on my local development server (Windows 7, Apache 2.2, virtual hosts configured), while it points to the correct path (C:/Local/MySite), nothing actually happens (favicon doesn’t work, stylesheets and images don’t get loaded, etc.)

Is there any way of getting $_SERVER[DOCUMENT_ROOT] to work locally?

I found that I can get the same expected result by using “http://&#8221; and $_SERVER[HTTP_HOST] (<link href="http://' . $_SERVER[HTTP_HOST] . '/favicon.ico" rel="icon" />), is there any downside to doing that? Alternatively, I can continue to use $_SERVER[DOCUMENT_ROOT] and just use server rewrite rules to parse it into something that will run locally, and leave it untouched for the browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:36:15+00:00Added an answer on June 1, 2026 at 8:36 am

    $_SERVER[DOCUMENT_ROOT] is the entire path to the website’s root directory and should fail spectacularly for links and images.

    Now, having said that, what you have so far is OK… except that $_SERVER[HTTP_HOST] only works if the connection is made using HTTP/1.1 and the client issues a Host header. $_SERVER[SERVER_NAME] should always work, though. Just be aware that $_SERVER[SERVER_NAME] will use the virtual hosts main address, so if a server has aliases…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that SQL server use memory cache for the all operations by loading
Do you think it is preferred to use $_SERVER['DOCUMENT_ROOT'] in website's include statements? Is
Can I use .htaccess to change the return value of $_SERVER['DOCUMENT_ROOT'] for local development
Like a lot of web developers, I like to use .htaccess to direct all
I use $_SERVER['DOCUMENT_ROOT']./lib/sft_required.php; to include the 'sft_required' file in a PHP script. When I
I'm using $_SERVER['DOCUMENT_ROOT'] for my include paths so files will figure out where they
I'm trying to link to a stylesheet in my header file using $_SERVER[DOCUMENT_ROOT] as
I use the following scheme to include PHP files: require($_SERVER['DOCUMENT_ROOT'] . Path/To/My/Website/Path/To/My/File.php); I would
When I try to use require or require_once , it will work fine if
I use SQL Server 2005. I have a simple logging table that my web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.