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
Link to root directory
Moderator: General Moderators
Re: Link to root directory
Print out $_SERVER and see if there's something in there that looks useful.
Re: Link to root directory
Start all your urls with /.
For example: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
For example:
Code: Select all
<a href = "/index.php">Home</a>Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Link to root directory
Thank you, I was making it more complicated than it is!
Re: Link to root directory
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);