Forum Moderators: coopster

Message Too Old, No Replies

include error

         

kumarsena

5:12 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



how can i make include files that works without concern for where the doc with the include is. say the i have a php doc deep in the file system inside loads of folders, but i have an include with menu itenms in the root, but when i include this in the file in the target file i get an error. this due to the fact that the links in the include link in the following form:

href="link.php3"

how can i add the server path so that the links work no matter ,where in the file system the fiels are located.

kumar

jatar_k

5:15 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<? include $_SERVER [ca.php.net]['DOCUMENT_ROOT'] . "/path/to/file.php";?>

kumarsena

5:26 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



thanks jatar_k

coopster

5:37 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Or you could use ini_set [php.net]. See these threads for more information:

php, templates and folder directives [webmasterworld.com]
Accessing PHP includes folder in root dir from 2+ levels deep [webmasterworld.com]

kumarsena

5:37 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



i tried what u posted, but when i still have problems.

my link.inc is in root, and i added

<? include $_SERVER['DOCUMENT_ROOT'] . "/link.inc";?>

to a file bands.php in a folder called stuff. but when i open bands.php then the links , instead of linking to the file guitar.php which is outside stuff, links to it as if it was inside stuff.

any suggestions?

jatar_k

5:41 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would that has to do with think link to that page.

all html links in included files need to be root relative as well.

<a href="/path/to/file.php">

or root files
<a href="/file.html">

kumarsena

5:50 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



oh,,,
that would make sense,.,.,.

thanks

Timotheos

5:53 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would that has to do with think link to that page.

Somebody get jatar_k a cup of coffee!

jatar_k

6:02 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, on my way ;)

I would think that has to do with the link to that page.

wow, I even reread it.

kumarsena

6:14 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



i have now this where i want the links to appear

<? include $_SERVER 'DOCUMENT_ROOT'] . "/link.php3";?>

and this is in m,y link.php3 file

<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/ph_album.php3"?>"> PHOTO ALBUM </a>
<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/cd.php3"?>"> CD REVIEWS </a>
<a class="menulink" href="<? include $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>"> STUFF </a>

would this make sense....cause all of a sudden when i load the first page that contains the include i get an error that apache has generatod error and will be closed by windows etc...

any idea if im, doing something wrong here...
im, gonn arestart the system, and try agian in the mean time

Timotheos

6:26 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your running a version of PHP earlier the 4.1.0 then you'll have to use $HTTP_SERVER_VARS instead of $_SERVER

Here's the part in the manual about server vars [php.net]

kumarsena

6:27 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



im running 4.3.3

jatar_k

6:33 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you don't an include there

<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/ph_album.php3"?>"> PHOTO ALBUM </a>
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/cd.php3"?>"> CD REVIEWS </a>
<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>"> STUFF </a>

<?= is shorthand for echo

kumarsena

6:43 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



i didnt get..sorry....

Timotheos

6:54 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



im running 4.3.3

Good. The php3 extension faked me out.

coopster

6:55 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Threw me for a loop, too. At first, I thought you wanted to use the PHP include() [php.net] function to include files. You are simply trying to use a relative path!

What jatar_k is saying is that you don't need the include function, you simply want to echo or print the value of the DOCUMENT_ROOT concatenated to the path you are specifying. Therefore, don't use

include
and echo the value out:

<a class="menulink" href="<?= $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>">STUFF</a>

is the same as:

<a class="menulink" href="<?php echo $_SERVER['DOCUMENT_ROOT'] . "/stuff.php3"?>">STUFF</a>

<?= is PHP shorthand for echo if short-open-tag [php.net] is ON.

kumarsena

7:01 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



oh i get it....i used the include,,,,a side effect of having a BEng in Copy and Paste Techniques...

thanks...

kumarsena

7:14 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



i think i need my daily dose of java...

kumarsena

8:02 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



ok guys...

i got this problem, now....the link.php3 include file is not loaded into my guitar.php3 file...

how come...?

im confuse now...

Timotheos

8:16 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you getting any error messages?

I don't know if this is it but back in message #10 this line was missing a bracket.
<? include $_SERVER['DOCUMENT_ROOT'] . "/link.php3";?>

kumarsena

3:53 am on Jan 22, 2004 (gmt 0)

10+ Year Member



i think i know now...the include statement i have in my welcome.php3 page is working. but NO other include on any page is working. including the ones in root. well, they are and they are not.

let me explain (i am kinda excited, having found my first answer to why a script is not working, he he). the welcome.php3 page (where the include is working) is called with the address [localhost...] but all the other pages are called using a link from this page.

and the links are created using the $_server['document_root']. so while the welcome page is being called "trough" the server, the other pages are not. why? becaue the
$_server['document_root'] returns

c:/program files/easyphp1-7/www/

and using this to call the file is not going "trough" the server. i kinda dicovered this when i just opened the welcome.php3 by double clicking on it in its folder. then i tried calling the other files by entering the URL in the address bar and there you go, the include statemnts worked.

so my question is....how do i avoid this, if there is a way...? and will it work on the host server...(its almost 4 am and i wanna go to sleep....cant be botheresd trying out just now...:)...).

thanks guys, and i hope my dicovery is of use at some point in time and place for some tested soul...

kumar

jatar_k

5:06 am on Jan 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry kumarsena,

partly my fault

when including it does using the filesystem so you need the DOCUMENT_ROOT part.

When outputting a link, you only need the path in relation to the root of the website.

so
<? include $_SERVER['DOCUMENT_ROOT'] . "/link.php3";?>

but in the file that is included you only need to reference from the root of the site for web links

<a class="menulink" href="/ph_album.php3"> PHOTO ALBUM </a>
<a class="menulink" href="/cd.php3"> CD REVIEWS </a>
<a class="menulink" href="/stuff.php3"> STUFF </a>

the conversation about include got me all confused

kumarsena

4:27 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



okie guys, it is now working just fine....thanks to all who helped...

just one final q tough....i asssume now there is a diffrence between linking like this "file.php" and this "/file.php" rite?

once again thanks
kuamr

jatar_k

4:41 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you have a link

file.php

you have specified that it is in the same folder as the present file.

when you start your path with a / you are saying start at the root.

If you do this in an href it will start at the root directory of the web site. If you are using filesystem functions like include or require it will start looking at the server root.

kumarsena

4:57 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



TNX jatar_k

kumarsena

7:04 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



everything was ok on localhost but on the server i ge the following

Warning: Failed opening '/home/p/pt/pt-home/public_html//link.php3' for inclusion (include_path='.:/usr/local/lib/php') in /mnt/home4/k/ku/kumar/public_html/welcome.php3 on line 56

this is line 56

<? include $_SERVER['DOCUMENT_ROOT'] . "/link.php3";?>

any advice..?

kumarsena

7:07 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



just a note: the file link.php3 is present in the public_html folder.

i also noticed this double slash

public_html//link.php3'
so i changed /link.php3 to link.php3 on line 56 (see above)

kumarsena

8:27 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



but problem still there....

jatar_k

8:32 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



those paths are different

/home/p/pt/pt-home/public_html/link.php3

/mnt/home4/k/ku/kumar/public_html/welcome.php3

if those two pages are in the same root it sure doesn't look like it

kumarsena

8:43 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



yeapp, they are...both files, welcome.php3 and link.php3 in the public_html root folder...