Jump to content

help: root path


delickate

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.