delickate Posted April 2, 2012 Share Posted April 2, 2012 Hi, I want to get root path and use on links even if i'm in sub to sub folder etc... suppose my site name is fitness.com and having two subfolder. so url will become http://www.fitness.com/dir/dir_sub here i want to put a link to go to root directory file. there are different ways to do that. e.g: <a href='../../filename.php'>go to that page</a> but i want to use some constant that always shows to root directory. as i defined here define("SERVER_NAME" , $_SERVER['HTTP_HOST']); //and used it like this <a href='<?php echo SERVER_NAME; ?>/filename.php'>go to that page</a> it works when we're on root directory. but when we go to sub directory it added sub directory name with it. which i don't want. is there any way? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260189-help-root-path/ Share on other sites More sharing options...
ocpaul20 Posted April 2, 2012 Share Posted April 2, 2012 there is a $_SERVER["DOCUMENT_ROOT"], and all kinds of PHP variables or like $var = dirname(__FILE__).'/'; for path to current directory etc I believe what most people do is to have various session variables which they set at the start. Quote Link to comment https://forums.phpfreaks.com/topic/260189-help-root-path/#findComment-1333538 Share on other sites More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 Just use define('SERVER_NAME' , 'http://www.fitness.com/'); //and used it like this <a href='<?php echo SERVER_NAME; ?>filename.php'>go to that page</a> Quote Link to comment https://forums.phpfreaks.com/topic/260189-help-root-path/#findComment-1333540 Share on other sites More sharing options...
delickate Posted April 2, 2012 Author Share Posted April 2, 2012 Thanks ocpaul20, but document root show the absolute path. which i don't want. i need virtual path. yea session is a great idea. Thanks dragon, You choose a smart move. I like it. the method will definitely work. Thank a lot. Thanks all of guys... it is really a help full. Quote Link to comment https://forums.phpfreaks.com/topic/260189-help-root-path/#findComment-1333632 Share on other sites More sharing options...
Psycho Posted April 2, 2012 Share Posted April 2, 2012 Just start the URL with a "/", that will always be relative to the root of the site. <a href='/filename.php'>go to that page</a> That will load the file "filename.php" from the root of the site regardless of the location that was called to create that page. Quote Link to comment https://forums.phpfreaks.com/topic/260189-help-root-path/#findComment-1333634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.