Shoutbox

Other PHP question... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Other PHP question... (/showthread.php?tid=27454)

Other PHP question... by leito on 06-20-2004 at 11:07 PM

Hi all, working on a PHP file, I include a file, which has a link, let's say:

in a.php:

$a = '<a href="index.php">Index</a>';

and in all other files in the same directory:

include 'a.php';

But, when I have files in other folders I use:

include '../a.php';

but index.php is not in that folder and I get an error.


This was a simple explanation,  really need that file to be the only one with the link, so I can't just added in each page.
Is there any php function that detect in which folder the file is? In big, because that's the really question.

something like:

echo $_SERVER['DOCUMENT_ROOT'] 
// But DOCUMENT_ROOT will echo the complete path, and not just the folder.

The document root directory under which the current script is executing, as defined in the server's configuration file.


RE: Other PHP question... by WDZ on 06-21-2004 at 04:11 AM

I think the simplest thing to do is put a slash (and a path, if necessary) before the file name (index.php). For example, this file has a link to "/index.php" and it will link to http://shoutbox.menthix.net/index.php no matter what folder it's in...

http://shoutbox.menthix.net/files/testing.html

quote:
Originally posted by leito.gt
echo $_SERVER['DOCUMENT_ROOT'] 
// But DOCUMENT_ROOT will echo the complete path, and not just the folder.
You should try this instead: dirname($_SERVER['PHP_SELF'])

If you're running the script http://site.com/files/images/index.php, that code will return "/files/images"
RE: Other PHP question... by leito on 06-21-2004 at 04:45 AM

quote:
Originally posted by WDZ

You should try this instead: dirname($_SERVER['PHP_SELF'])

If you're running the script http://site.com/files/images/index.php, that code will return "/files/images"

Thnx, I think I could ask if (directory is this) link=index.php else link=../index.php ....
RE: Other PHP question... by KeyStorm on 06-21-2004 at 01:51 PM

Well, you can also use: 'http://'.$_SERVER['SERVER_NAME].$_SERVER['PHP_SELF'] to get the current path to the current script.
Some testing around with includes won't hurt you, either ;).