Jump to content

Getting to the domain name with $_SERVER['DOCUMENT_ROOT']


markkanning

Recommended Posts

Hey all,

Before I end up with an imprint of my head on my office wall(and a really band headache), can someone tell me what the actual $_SERVER code is that will output the "domain name" root as opposed to the server root? In other words, I want to output "http://www.domain.com" instead of "/user/blah/m/q/stuff/morestuff/htdocs/".

 

No PHP site seems to have a good answer for this.

 

mark

Here is what I use. So all my links can be absolute without me having to type it all in everytime I use this

 

<?php $root='http://'.$_SERVER['HTTP_HOST'].'/' ; ?>

 

if you echo $root, it will output http://your_domain.ext/

 

Check out the manual for the $_SERVER reserved variables.

 

http://us2.php.net/reserved.variables

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.