Q:

Using $_SERVER to get the webroot

I am using following code in the cakephp project in bootstrap to define constants like webroot path. Is it right 
$_ROOTPATH  = strtolower('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
$URLPART    = explode('cake',$_ROOTPATH);

define('ROOTPATH',$URLPART[0].'cake/');
define('RESOURCEBASEPATH',$URLPART[0].'resources/');
define('DOCUMENTROOTPATH',substr($_SERVER['SCRIPT_FILENAME'],0,-9));

ROOTPATH in place of $this->webroot . 
DOCUMENTROOTPATH pointing to actual to piont to the actual path as in /var/www/

What do you say about this.  Any note/suggestion is welcome. 

A:

Regarding file paths, have you looked at the existing core constants? You will probably find most of the file path constants you need are already defined there.
For example, your DOCUMENTROOTPATH is exactly the same as (I believe) the WWW_ROOT constant.
As for URLs, CakePHP's Router::url() takes care of handling all URLs in a consistent manner (eg. URLs output by Controller::redirect(), FormHelper, HtmlHelper, etc.)
You can also call Router::url() statically wherever you need to create URLs:
echo Router::url('/some/random/path');
// output: http://www.example.com/path/to/cake/some/random/path
echo Router::url(array('controller' => 'abc', 'action' => 'xyz'));
// output: http://www.example.com/path/to/cake/abc/xyz

Unless I am missing something, I would just use the above instead of littering your application with the likes of ROOTPATH and RESOURCEBASEPATH. For example the following approaches are equivalent:
$this->redirect(ROOTPATH . 'some/place'); // your way
// takes you to: http://www.example.com/path/to/cake/some/place
$this->redirect('/some/place'); // cake way
// takes you to: http://www.example.com/path/to/cake/some/place

echo $this->Html->image(RESOURCEBASEPATH . 'some/image.jpg'); // your way
// outputs: <img src="http://www.example.com/path/to/cake/resources/some/image.jpg" />
echo $this->Html->image('some/image.jpg'); // cake way
// outputs: <img src="http://www.example.com/path/to/cake/img/some/image.jpg" />
echo $this->Html->image('../resources/some/image.jpg'); // cake way
// outputs: <img src="http://www.example.com/path/to/cake/resources/some/image.jpg" />

