Finding Paths on PHP | 2012-05-05

Technology Blog » Web Development

Just wanna keep a good note for determine paths.
Let say the Full URL is: http://www.pcinvent.com/page?id=1&action=a


/var/www/pcinvent_com (May very if your server absoulte path is different)

$_SERVER["DOCUMENT_ROOT"]

www.pcinvent.com

$_SERVER['HTTP_HOST']

id=1&action=a

$_SERVER['QUERY_STRING']

Array ( [scheme] => http [host] => www.pcinvent.com [path] => /page [query] => id=1&action=a )

parse_url("http://www.pcinvent.com/page?id=1&action=a")

Ok, what to do if you use CodeIginiter framework to get http://www.pcinvent.com/ (Note that "/" at the end is included)
First, load the url Helper in Controller.

$this->load->helper('url');
Then, ready to use:
echo base_url();