Page 1 of 1

Link to root directory

Posted: Tue Oct 20, 2009 12:40 pm
by kinger88
Hi all,

Can anyone tell me a way of directly linking to the root directory (the public html folder) ?

I've tried $SERVER["DOCUMENT_ROOT"] but this gives the directory this code is in rather than the public html folder.

I want to use this in an included footer, which links to the index but on some pages it would need to be ../index.php and in others it would need to be ../../index.php etc etc so I need a way of linking to the route directory from which ever directory I am currently inside.

Hope I have explained that well enough.

Cheers
Steve

Re: Link to root directory

Posted: Tue Oct 20, 2009 1:09 pm
by requinix
Print out $_SERVER and see if there's something in there that looks useful.

Re: Link to root directory

Posted: Tue Oct 20, 2009 2:22 pm
by pickle
Start all your urls with /.

For example:

Code: Select all

<a href = "/index.php">Home</a>
will work on a page at http://www.yourdomain.com/dir/page.html, and also http://www.yourdomain.com/a/few/levels/in/page.html

Re: Link to root directory

Posted: Sun Oct 25, 2009 2:48 pm
by kinger88
Thank you, I was making it more complicated than it is!

Re: Link to root directory

Posted: Sun Oct 25, 2009 3:36 pm
by keevitaja

Code: Select all

define(DIR_SEP, DIRECTORY_SEPARATOR);
define(PATH, dirname(__FILE__).DIR_SEP);
 
$url_path = str_replace(str_replace('\\', '/', $_SERVER["DOCUMENT_ROOT"]), '', str_replace('\\', '/', PATH));
$url_path = (ereg('^/', $url_path)) ? $url_path : '/'.$url_path;
define(URL_PATH, $url_path);
unset($url_path);