best way to access/create SITE_ROOT and SERVER_ROOT values in PHP?

Posted by Haroldo on Stack Overflow See other posts from Stack Overflow or by Haroldo
Published on 2010-06-03T07:27:17Z Indexed on 2010/06/03 7:54 UTC
Read the original article Hit count: 133

Filed under:

I need 2 different paths, one for includes and one for js/css etc. I'm using mod_rewrite. The below works fine....

Currently all my files contain this at the top

define('SERVER_ROOT',   'C:/wamp/www/site_folder/');
define('SITE_ROOT',     'http://localhost/site_folder/');

and then files are called like so:

require_once SERVER_ROOT . 'st_wd_assets/inc/func_st_wd.php';    

<link rel="stylesheet" type="text/css" href="<?php echo SITE_ROOT;?>st_pages/user_area/css/user_area.css" media="screen"/>

as you can probably see, it's going to be a massive chore to update the top of every file everytime i move versions between the localhost and my live server.

What's the best/standard way of defining these ROOT values?

I can't see a solution in the $_SERVER super global? Do people normally just use VirtualHosts? But then wouldn't it still be necessary to define ROOT constants?

© Stack Overflow or respective owner

Related posts about php