Sanket,
I have encountered the same problem in many of my sites and have devised a simple scheme (some might say dumb). Setting up an absolute or relative path on the server does me no good as I want to be able to move my site or branches of a site about as I feel. I also test on a local Windows server and usually move to a Unix server, where paths differ. I resolve it like this:
Every page has a level set in the top of the file. $level=0; or nothing indicates root of the site while $level=1; is a subdirectory, $level=2 a sub-subdir and so on.
I a file used by all pages (common.php, header.php or whatever you have already) I compute a variable called $pre, which contains a string 'leading' to the root. This could be "../" for $level==1 or "../../../" for $level==3.
My crude routine looks like this:
switch ($level) {
case 0:
$pre="";
break;
case 1:
$pre="../";
break;
case 2:
$pre="../../";
break;
case 3:
$pre="../../../";
}
It could probably be done much smarter, but this I understand - and it works...
The same common file contains a small function called includefile(), It looks like this:
function includefile($filename)
{
GLOBAL $pre;
include($pre.$filename);
}
I know globals are not always popular, but again - it works. I then use includefile() in stead of include() and give the name of the file relative to the top of my site as a parameter, like
includefile('lib/database.php'); or
includefile('subjects/overview/list.inc');
As long as I remember to give the $level variable the correct value, this works well.
Hope it helps you
Martin