What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Other PHP question...

Other PHP question...
Author: Message:
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. Wink  Other PHP question...
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.


This post was edited on 06-20-2004 at 11:07 PM by leito.
[Image: leonelgalan.png]
06-20-2004 11:07 PM
Profile E-Mail PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: Other PHP question...
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"

This post was edited on 06-21-2004 at 04:19 AM by WDZ.
06-21-2004 04:11 AM
Profile PM Web Find Quote Report
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. RE: Other PHP question...
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 ....
[Image: leonelgalan.png]
06-21-2004 04:45 AM
Profile E-Mail PM Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
RE: Other PHP question...
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 ;).
06-21-2004 01:51 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On