Jump to content

Define Server Variable


blsn

Recommended Posts

Hi,

 

I am building a web site and have included files that get used from the root and different sub directories within my site. For example:



<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/css/style.css">


 

These are the outputs of $_SERVER['DOCUMENT_ROOT']:

 

Testing  server (http://localhost/mywebsite):

C:/xampp/htdocs/mywebsite

 

Share host server (http://www.mywebsite.com):

/home/mywebsite/public_html

 

How to define the above path correctly to work both on testing and hosting server?
Link to comment
https://forums.phpfreaks.com/topic/277618-define-server-variable/
Share on other sites

$_SERVER['DOCUMENT_ROOT'] is the file system (disk) path to your document root folder. it is NOT used in html links/href statements on a web page. you must use a URL in links/href statements.

 

you can use a domain relative URL - href="/css/style.css" (the leading slash refers to the root of the domain of the current page.)

 

or you can use an absolute URL - href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/css/style.css"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.