Forum Moderators: coopster

Message Too Old, No Replies

PHP includes and navigation

To what page are the links relative to?

         

Marshall

2:53 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This may be painfully obvious, but I think I am suffering from temporary brain-dead. And since I am new at PHP, I would appreciate the help.

I know when doing includes, it's best to have it
<? inlcude$_SERVER['DOCUMENT_ROOT']. "/nav.htm?;>

What I can't seem to think through is what are the links relative to? Is it the location of the nav.htm page or the page.php page? In other words, there's no problem if the page.php is at the root level along with the nav.htm page, but if page.php is located at root/file/file/page.php and the include nav.htm is in the page, to which page are the links relative? Make sense?

Or is it simpler to just use absolute URL's?

DrDoc

3:14 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Links are relative to the initial page. For example, if you have a page (first.php) that includes second.php -- all links are relative to the file path of first.php, no matter the location of second.php, and no matter if second.php contains links or not. When doing
include
, it is as if second.php was cut and pasted into first.php.

Marshall

5:27 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So to be safe, use absolute URL's is what I assume you are saying.

Thanks for the help.

tomda

5:54 am on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, best is to use absolute URL.

But, you could also check with you server to find out if they have configurate an include_path - ini_get("include_path");

In such case, you can just create an include folder - most of the time called include(s) - in www root.
Then everytime you can an include - include_once(text1.php) - it will look in the include folder first. If not found, then it follows the rules described above.

Cheers