I have this class:
class PageBuilder {
public function GetHeader() {
include(dirname(dirname(__FILE__)) . '/template/header.php');
}
}
Which when called will insert the header file into my page. All is good.
$page_builder->GetHeader();
In the header.php is the top of the HTML file which includes a menu. My problem is, depending on where the PageBuilder gets called from changes the menu link URLs.
How do I make sure they are always relative to the root folder.
dirname(__FILE__) doesn't work because it turns the URL into file:///, also I really don't want to append the entire http://www.blahblah.com/blah because if it is relative to the root it doesn't matter about any of that.
EDIT
So as someone posted you can use $_SERVER[''] but which one is reliable, no doubt PHP will have put in some blinding caveats.
See I was thinking $_SERVER['SERVER_ADDR'] or $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST'] .....
Going $_SERVER['HTTP_HOST'] for now .. result is fail.
Just prefixing with / resolves to the localhost root so my links are localhost/admin/profile.php rather than localhost/TestApp/admin/profile.php, Do I have to actually specify that it sits in folder named TestApp?