Php absolute and relative paths with builtin functions

How do i get relative and absolute paths with global functions and variables. I have seen in cms like wordpress and joomla, whenever we install it, it stores paths in config.php files accurately whether we have installed it in parent domain or in sub-domain.
I tried but failed to make such function that can extract correct path working for any directory that user is installing my script. Can anybody suggest that?

If you want your current directory you can use the dirname() function.

echo dirname( __FILE__ ) . '<br />';
// ouput: /home/user/www/htdocs

If you want the parent directory:

 echo dirname( dirname( __FILE__ ) );
// ouput: /home/user/www

Is this what your are looking for?

Its fine for internal script usage to include files.
What about path that generates in URL i.e : http://localhost/mydir/mydir2/abc/myproject/ OR
I dont know how wordpress and other cms gets this exactly correct. How can I have such url as I am gonna need it when I will create installer for my script.

You can use the $_SERVER array, specifically the $_SERVER[‘SERVER_NAME’] and the $_SERVER[‘PHP_SELF’] array keys. If you do a var_dump() on the $_server array you will find a ton of useful information.

I’m sorry I didn’t answer sooner, it was a very long weekend. I didn’t even get a chance to turn the computer on.