Jump to content

how do i point to an absolute root


jeff5656

Recommended Posts

Because I have include files in a subdirectory called "incl", I cannot rely on using relative paths because that include file is in a header on and the pages are in multiple subdirectories (or in the root).  I need some way to get the location of the root (the one where my index file is located).  I want to use something like this:

 

$path= $_SERVER['DOCUMENT_ROOT'];
include $path."/subdirectory/file.php";

 

However, when I use $_SERVER['DOCUMENT_ROOT'] I get :

/home/content/j/p/f/name55/html/

 

which is not where the index file sits.

Any ideas on how to get the directory where my index file sits? (i.e. the index that gets read when you got to www.domain.com)

 

Link to comment
Share on other sites

If your index.php is loaded first then all paths will be relative to the index.php file.

 

What do you mean by loaded?  Sometimes they will go to a page located in a different subdirectory (or even land there if they bookmarked that).  In that case, the included file will no longer be pointing to the root directory.

 

Of those out there that have include files in a separate subdirectory, how do you handle those files pointing to the correct location?

 

example: in the index.php you have:

include "links.php";

 

and in links.php you have:

<a href="/subdir/file.php">Click me</a>

 

So in index.php this will work, but lets say I am in a subdirectory off the root called ad and I have this file

example.php

include "links.php";</php]

 

This won't work becasue it will try to do: <a href="ad/subdir/file.php">Click me</a>

 

 

 

Link to comment
Share on other sites

thats where the document_root comes...

 

lets suppose you have a file structure like this

 

[root]

=>index.php

[subdir]

=>file.php

[ad]

=>index.php

 

now in root you would just call include('subdir/file.php');

 

but in the ad index.php you would include($_SERVER['document_root']."/subdir/file.php");  or include('../subdir/file.php');  though the document_root method is more viable.

Link to comment
Share on other sites

Well the problem is one of the included files in is a form with action ="logout.php"

 

So if I am in the index when I press logout it works, but if I am in a subdirectory it won't work.

How do I fix that?  In DOS (remember that OS?) I could just type action = c:\ad\logout.php andit would work no matter where I was.

How do I do the same thing here?

 

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.