Jump to content

why $_SERVER['DOCUMENT_ROOT']; sometimes works??


samoht

Recommended Posts

hello again,

 

I would like to be able to use

$docRoot = $_SERVER['DOCUMENT_ROOT'];

 

to define my path fully when linking pages. for some reason this works fine on the live server, and fine on my laptop (which uses wamp and the server name is localhost) but on my work test server )that is networked) the path always shows a C:// etc

 

Why is this ??

And can I fix-it??

Link to comment
Share on other sites

Hey there,

 

if you are trying to use the document root for pages you will run into trouble every time. The document root refers to actual root defined in the server configuration. Using the document root is helpful for includes and file commands in php (among many other things), just not html linking.

<a href="/example.php">example</a>

 

the above code should go to your web root (meaning the folder that is available for the users to see). if this doesn't get you directly to your root, then the server may need a variable to be set. usually these are set your environment vars.

 

ref: http://us.php.net/getenv

 

good luck

Link to comment
Share on other sites

the problem is that I have some nested pages and I don't want to

have "../../../"

 

but would much rather have a variable that starts the path correctly,

 

so if live is www.live.com/

 

local(my laptop) is localhost/clientname/html/

 

and work is workserver/Clients/clientname/html/

 

I could just put the variable in to work for each case. I know I can set up a variable in a switch case exactly like this, but then for each client I have to physically change the name - it would be nice to just be able to use document root or something that fills in the first part of the url no matter what machine I am on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.