PDA

View Full Version : universal include code


duniyadnd
11-29-2002, 01:05 PM
I was going through the manual on php.net for the include function

Link (http://www.php.net/manual/en/function.include.php)

and got even more confused on what is the best way of creating a universal code for an include. ie. If i'm in directory "foo", i can call the include from its directory which is one directory down. I want to use the same command if I was in the same directory as the file I want to include. (basically a universal script to call in my include files).

I thought it might be similar to SSI scripts, where I can just create a "virtual" but apparently that's not the case.

Any thoughts?

While we're on this topic, what is the best way of including includes in files that are included. A little alliteration for everyone there, if it made any sense. ;)

Thanks
Duniyadnd

duniyadnd
11-29-2002, 01:29 PM
what i figure is to add an pre-extension for each one, ie. add the name of my localhost prior to linking it.

include ''.$url.'includes/something.php';

that seems to work fine. Are there any other ways?

Duniyadnd

firepages
11-29-2002, 11:43 PM
thats pretty much it, or $DOCUMENT_ROOT

include($_SERVER['DOCUMENT_ROOT'].'include/file.php');

on *NIX that will translate to (eg)

/home/user/www/include/file.php
and on win32 (eg)
C:/apache/htdocs/include/file.php

there are other ways, but your or the above methods are probably safest/easiest.